|
|
|
Flash Macro > Organizing Library using JSFL
Author: Saumitra Karandikar | Email
Advertisement
True in the end indicates that if the item already exists, overwrite it. This is a matter of choice and may be set to false, if required.
The complete "for" loop that runs on the Library looks as follows:
//Comments : Begin
//iterate through the Library items in the library
//iIdentify type of the item and move it to the respective folder
//The miscellaneous category represents anything that is not a graphic or movie clip // or button - if the item type is folder it is ignored
//The miscellaneous item could be another folder or component
//Comments : End
for(var i=0;i
myItem = itemArray[i];
myItemType = myItem.itemType;
myItemName = myItem.name;
fl.outputPanel.trace(myItemType +">>"+myItem);
if(myItemType == "sound"){
mylibrary.moveToFolder("Audio", myItemName, true);
}else if(myItemType == "button"){
mylibrary.moveToFolder("Buttons", myItemName, true);
}else if(myItemType == "graphic"){
mylibrary.moveToFolder("Graphics", myItemName, true);
}else if(myItemType == "movie clip"){
mylibrary.moveToFolder("Movie Clips", myItemName, true);
}else if(myItemType == "folder"){
}else{
mylibrary.moveToFolder("Miscellaneous", myItemName, true);
}
}
The loop uses the if..else if..else conditional statements to put library items into respective folders depending on the type. A switch statement could have also been used here to replace if..else if..else loop.
Finally, We save this file at an appropriate location. If you want this to be available as a command under the "Commands" drop down menu the next time you start Flash, save the jsfl in the folder:
Program FilesMacromediaFlash MX 2004enFirst RunCommands
In my case it is:
C:Program FilesMacromediaFlash MX 2004enFirst RunCommands
Cool, now that we are through with the code lets see it in action. Open any FLA file, which you feel, needs "organizing". Go to "Commands > Run Command". A "browse file" type dialog pops up. Choose the recently created jsfl file. And see the folders getting created automatically and appropriate elements being moved to appropriate folders.
The jsfl file "organize_library.jsfl" is available along with this tutorial.
As an extension to this simple "macro", you may also use the Library object to arrange the library in an alphabetical order, or remove specific type of items from the library like sounds. You may also want to update all the items before the each publish. You may also modify it to rename all library items to have a prefix attached to each item name.
Download Source File
We hope the information helped you. If you have any questions
or comments, please don't hesitate to post them on the
Forums section
Submit your Tutorial at Click Here
|
|
|