Moving Library Assets from FLA to FLA with JSFL
One of my latest projects had me scratching my head while I was doing my R&D. The project was to build a Flash panel that could pull assets in from another FLA that acts as a library. My first thought was to see if there was any way to copy items directly out of the library and add or paste them into the current working FLA. In my research this just isn’t possible, but I was still able to get the panel built.
Basically the process that works is as follows:
- Open the library FLA file
- Put the wanted library item on the stage with library.addItemToDocument()
- Use fl.getDocumentDOM().clipCut() to add the item to the clipboard
- Close the library
- Use fl.getDocumentDOM().clipPaste() to add the asset to the FLA
It seems pretty simple and it is, truly the hardest part was figuring out that that was the process to use. Here’s what my JSFL looks like:
//Loads an asset from the libraryFile into the current working FLA
//libraryFile - the filename of the library (icons.fla)
//AssetName - the asset name as it is in the FLA library
function LoadAsset( libraryFile, AssetName ) {
var originalDoc = fl.getDocumentDOM();
fl.openDocument( librariesPath() + libraryFile );
var libDoc = fl.getDocumentDOM();
fl.getDocumentDOM().library.addItemToDocument({x:0,y:0}, AssetName);
libDoc.clipCut();
fl.closeDocument(fl.getDocumentDOM(), false);
originalDoc.clipPaste();
}
//this is where I'm keeping the library FLA files
function librariesPath() {
return fl.configURI + 'Resources/AssetLibraries/';
}
And here’s the panel:

The way it all works is the panel loads an XML file that defines all the library files and populates the combo box. Then when a file is selected from the combo box, I have another JSFL function that opens the FLA and grabs all the top-level (not in folders) asset names from the library and returns them back to the panel as a comma delimited string. The string is broken up into an array and populates the asset list. The ‘Add to Stage’ button then uses the name in the list to call back to the JSFL referenced above.
Hope this helps anyone looking to do this, I found no help on this via Google in my own research.