Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Batch export images from Library?

i have a flash .fla that was compiling as a .swc with references to images, but now I need to load all these images externally and I dont have the original assets.

I know I can export them one by one, but I have a few hundred in the file, and want to find an easier way.

Any help would be awesome.

like image 505
Conor Avatar asked Apr 24 '10 22:04

Conor


1 Answers

You can use this script. It exports only bitmaps from your library.

//created by Heitara
var folderURI = fl.browseForFolderURL('Select folder where all images should be exported as *.PNG');

var doc = fl.getDocumentDOM();
var newDoc = fl.createDocument();
//fl.outputPanel.trace("Init");

if(doc && newDoc)
{
    fl.outputPanel.trace("Start");
    var library = doc.library;
    var allLibItems = library.items;
    var item;
    var c = 0;
    var selectedItemOnStage;
    var selectionArray;
    var itemName;

    for (var i = 0; i<allLibItems.length; ++i) 
    {
        item = allLibItems[i];//only images will be processed
        if(item.itemType == "bitmap") //|| item.itemType == "graphic")
        {
            // attach image
            newDoc.addItem({x:0.0, y:0.0}, item);

            //postition all items on (0,0) 
            var image = newDoc.getTimeline().layers[0].frames[0].elements[0];
            if(image)
            {

                var hpx = image.hPixels;
                var vpx = image.vPixels;

                newDoc.width = hpx;
                newDoc.height = vpx;
                // we need to reposition the image, otherwise it will be centered
                image.x = 0;

                image.y = 0;
            }

            itemName = item.name.split('.')[0];
            //export as png
            newDoc.exportPNG(folderURI + "/"+itemName +".png",true,true);
            //select all
            newDoc.selectAll();
            //remove selection
            newDoc.deleteSelection();
            //deselect everything
            newDoc.selectNone();
            //output.trace("[END]");

        }

    }
}

//close the new document withut saving it
fl.closeDocument(newDoc, false);

Just save it as .jsfl file and open it from flash. You should also open the .fla file from which you want to export all images.

Best, Emil

p.s. Other solutions is to just rename the .fla to .zip(.rar) file and to extract all assets. This is applicable only to .fla files created with latest version of Flash CS5 or CS5+.

like image 195
Heitara Avatar answered Oct 06 '22 21:10

Heitara