Avg. Rating 5.0

Problem

You have a FLA file that has bitmap and/or audio files in the Library, and you need to extract them so you can edit them outside of Flash.

Solution

Use a JSFL script to save the bitmaps and/or audio to a folder on your hard drive.

Detailed explanation

Sometimes, bitmap and audio files that were imported into a FLA file are no longer available as separate files. While Flash has some ability to let you edit those files (e.g. in Photoshop), you may want to extract them from the FLA file so you can have a backup before you make your changes. Also, if you're working with a larger number of files, it can be very time-consuming to select "Edit in Photoshop" for an image, do your edits, then return to Flash and repeat that for all of the other images.

To solve this, we can use JSFL to extract bitmap and audio files from the FLA and save them to a folder on your hard drive. If you've  To do this, create a new JSFL document from within Flash, and enter the following code into the document. The comments will explain what's happening at every step of the way:

// 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") {
  imageFileURL = imageFileURLBase + "/" + libItem.name;
  var success = libItem.exportToFile(imageFileURL);
  fl.trace(imageFileURL + ": " + success);
 } 
}

Save the file to the Commands folder for Flash CS5, the location of which will depend on your operating system: [USER]/[AppSupport]/Adobe/Flash CS5/{Language}/Configuration/Command. The command will now be visible under the Commands menu in Flash CS5.

To use the command, open a FLA file and select the command from the Commands menu. If you've preselected some bitmaps or audio assets in the Library, only those will be extracted. If you want to go through the entire library to extract every bitmap and audio file, deselect all items in the Library first.

+
This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License. Permissions beyond the scope of this license, pertaining to the examples of code included within this work are available at Adobe.

Report abuse

Related recipes