View Full Version : help with automating import process of bitmaps and converting them to movieclips
jimdasaint
04-21-2007, 05:30 PM
Hi, I would like to import lots of bitmaps from a folder to the library and then I also want to create movieclips of each of them and giving them the same name of the file plus adding the word "mc_" to the beginning of the moveiclip name. Also the linkage ID name would be equal to the file name plus "mcID_" at the beginning of the moveiclip name.
Setting up each of them to be a movieclip would take a long time if I individually have to deal with lots of images.
So for example: "background.jpg" would be imported and would be converted to a movieclip symbol with the name "mc_background" and the linkage ID name of that movieclip would be set to "mcID_background".
I do not need to place them on the timeline but I want them to be available in the Library panel.
I am a designer not programmer and I have not used JSFL at all so I would need some down to earth assistance on how to achieve the above mentioned automation.
Thank you in advance,
Jim
bigevilbrain
05-03-2007, 10:49 PM
This is pretty close to what you need. It will convert all selected bitmaps to movieclips. The only difference is that you have to manually import the images to the stage. Then select them and run this script.
Also, it will add "bit" before the name and also strip the file extension. For instance: "background.jpg" becomes "bit - background" and the linkage is "bit_background". (You can change it to "mc" and "mcID" if you wish.)
So, copy this code and save it in a ".jsfl" file in the "Commands" folder. Enjoy!
// ----------------
// BITMAP TO SYMBOL
// ----------------
//
// VERSION: 1.1
// DATE: 9/18/06
//
// HOTKEY:
if (fl.getDocumentDOM() == null) {
fl.trace("Error: No document open.");
} else {
if (fl.getDocumentDOM().selection.length == 0) {
fl.trace("Error: Nothing selected.");
} else {
var selArr = fl.getDocumentDOM().selection;
for (var i = 0; i < selArr.length; i++) {
var instanceRef = selArr[i]
if (instanceRef.instanceType == "bitmap") {
// Only convert selected bitmaps.
var libraryItemRef = instanceRef.libraryItem;
var newName = "bit - " + stripExtension(libraryItemRef.name);
fl.getDocumentDOM().selectNone();
fl.getDocumentDOM().selection = new Array(instanceRef);
var mc = fl.getDocumentDOM().convertToSymbol("movie clip", newName, "top left");
if (mc == null) {
// Throws an error, on screen anyway...
fl.trace("Error: Couldn't convert "+newName+" to symbol.");
}
// Set linkage data
mc.linkageExportForAS = true;
mc.linkageExportInFirstFrame = true;
mc.linkageIdentifier = "bit_" + stripExtension(libraryItemRef.name);
}
}
fl.getDocumentDOM().selectNone();
}
}
function stripExtension(str) {
var pos = str.lastIndexOf(".");
if (pos == -1) {
return str;
} else {
return str.slice(0,pos);
}
}
myFUD
05-11-2007, 08:01 PM
This works great for Flash 8. But in Flash 9 there is a problem. I Have imported bitmaps from a layered psd so that the reference "libraryItemRef.name" is different than if the bitmap was brought in individually. It uses the original name of the psd and not the layer name (the name of the bitmap it creates).
Does anyone know what the reference for "libraryItemRef.name" would be in this case? A logic statement would be needed to be able to tell the difference between the way the bitmaps were imported.
|
vBulletin® v3.8.4, Copyright ©2000-2009, Jelsoft Enterprises Ltd.