View Single Post

#1
Bookmark and Share!
[JSFL] Organizing library items
Old 2008-08-08

A long time ago Nutrox posted a thread with details on he organizes his library items in Flash, which I set mine up similarly. I couldn't find the thread so I have to start a new one. Here is a jsfl script that I wrote that will create a folder structure:

lib
---- clips
---- bitmaps
---- fonts
---- media

Anytime you run the script it will put all your items in the correct folder. I didn't create a folder for "buttons" because I don't use them and prefer to use mc's. Also when you import a png, Flash creates a graphic symbol for the image. When you run the script it will delete that symbol since I haven't come across a time when it was needed. This is my first time working with jsfl so if my code is a bit sloppy please let me know how to optimize. I did run tests and it works fine and it does work correctly.

Code:
var dom = fl.getDocumentDOM();

if( dom == null || dom == undefined )
{
    alert( "Document Object is null and cannot be accessed" );
}
else
{
    createLibrary();
    cleanLibrary();
}

function createLibrary()
{
    dom.library.newFolder( "lib/bitmaps" );
    dom.library.newFolder( "lib/clips" );
    dom.library.newFolder( "lib/fonts" );
    dom.library.newFolder( "lib/media" );
}

function cleanLibrary()
{
    var libraryItems = dom.library.items;
    
    var i = libraryItems.length;
    
    while( i -- )
    {            
        if( libraryItems[ i ].itemType == "movie clip" )
        {
            dom.library.moveToFolder( "lib/clips", libraryItems[ i ].name, true );
        }
        else if( libraryItems[ i ].itemType == "bitmap"  )
        {
            dom.library.moveToFolder( "lib/bitmaps", libraryItems[ i ].name, true );
        }
        else if( libraryItems[ i ].itemType == "font" )
        {
            dom.library.moveToFolder( "lib/fonts", libraryItems[ i ].name, true );
        }
        else if( libraryItems[ i ].itemType == "sound" || libraryItems[ i ].itemType == "video" )
        {
            dom.library.moveToFolder( "lib/media", libraryItems[ i ].name, true );
        }
        else if( libraryItems[ i ].itemType == "graphic" )
        {
            dom.library.deleteItem( libraryItems[ i ].name );
        }
    }
}
I'm going to eat your brain and gain your knowledge.
postbit arrow 1 comment | 982 views postbit arrow Reply: with Quote   
Isocase
Registered User
Isocase is offline
seperator
Posts: 1,441
2006-11-03
Age: 28
Isocase's Avatar
seperator

Ultrashock Member Comments: