是否可以使用jsfl从Flash库导出声音文件?

时间:2012-08-10 20:49:32

标签: flash export jsfl

我发现这个脚本看起来像我需要的那样,但是,当我尝试导出文件时,我得到“filename:false”作为输出。有什么想法吗?

http://cookbooks.adobe.com/post_Extract_bitmaps_and_audio_from_a_FLA_file-18144.html

1 个答案:

答案 0 :(得分:2)

我找了一点,但我发现了你的问题。问题在于声音文件的这个小属性:soundItem.originalCompressionTypeYou can find some detail for the issue here。您的代码中发生的是它将尝试将声音文件导出为库中存储的类型。即filename.mp3保存为.mp3文件,filename.wav保存为.wav文件。如果soundItem.originalCompressionType等于“RAW”,则无法将声音文件另存为.mp3文件,因此输出“filename:false”。您必须将文件另存为.wav文件。我在定义imageFileURL时对代码进行了一些修改。

// Result of attempts to export will go to the output panel,
// so clear that first fl.outputPanel.clear();

// If bitmaps/audio in the library have been selected, export only
// those. Otherwise, export all bitmaps/audio in the library.

var lib;
if (fl.getDocumentDOM().library.getSelectedItems().length > 0) {
    lib = fl.getDocumentDOM().library.getSelectedItems(); 
} else { lib = fl.getDocumentDOM().library.items; } 

// Get destination directory for files 
var imageFileURLBase = fl.browseForFolderURL("Select a folder."); 
var imageFileURL; 

var totalItems = lib.length;
// Iterate through items and save bitmaps and 
// audio files to the selected directory.
for (var i = 0; i < totalItems; i++) 
{
    var libItem = lib[i];
    if (libItem.itemType == "bitmap" || libItem.itemType == "sound") 
    {
        // Check the audio files original Compression Type if "RAW" export only as a .wav file
        // Any other compression type then export as the libItem's name defines.
        if(libItem.itemType == "sound" && libItem.originalCompressionType == "RAW")
        {
            wavName = libItem.name.split('.')[0]+'.wav';
            imageFileURL = imageFileURLBase + "/" + wavName;
        } else {
            imageFileURL = imageFileURLBase + "/" + libItem.name;
        }
        var success = libItem.exportToFile(imageFileURL);
        fl.trace(imageFileURL + ": " + success);
    }
}