Flash JSFL, how to replace/update a bitmap item with a image file with different name

897 views Asked by At

I have many FLAs. For each fla, i need to replace some images with local image files. Those local image files do not have the same name as original imported.

I know it can be done manually: right click the item in library -> properties -> import.

But, there are too many FLAs, and too many images. And i need to do that replacement again and again once some FLAs change. So, i plan to write a jsfl to do that repeating task. I can configure the replacement with a map(itemName->replaceingFileUri). But, i don't know how to re-import a image using jsfl.

I have try this:

var itemName = 'name of the item to be replaced';
var imageFileUri = 'uri of the replacing local image file';
var lib = fl.getDocumentDOM().library;
lib.selectItem(itemName);
var item = lib.getSelectedItems()[0];
item.sourceFilePath = imageFileUri; // this do not work
lib.setItemProperty('sourceFilePath', imageFileUri); // this do not work too
lib.updateItem(item.name);
1

There are 1 answers

0
Mike Boltyshev On

U should try to replace existed in libdrary item with imported one In this example u select some img in subfolder in IDE, then run script and choise external image to import, then they will replaced.

var doc = fl.getDocumentDOM();
var lib = doc.library;
var item = lib.getSelectedItems()[0];
re = /(.*)(\/)(.*$)/;
var itemstr = re.exec( item.name );
var cname = itemstr[3];
var cpath = itemstr[1];

var fileURL = fl.browseForFileURL("select"); 
re = /(.*\/)(.*$)/;
var filestr = re.exec( fileURL);
doc.importFile(fileURL, true);
lib.selectItem( filestr[2] );
lib.renameItem( cname );
lib.moveToFolder( cpath, cname,  true )