Using JSFL to auto-name instances of newly created MovieClips

February 1st, 2008 by Steven Sacks

One of the pains I have with the Flash IDE is when I create a new MovieClip and name the symbol, I have to retype the name of the instance I just made. It's annoying and I wish Flash had an option to do it by default, but no worries. JSFL is here to save the day (again).

I wrote this script, saved it to the Commands folder, assigned it to F8 (assigned the old create symbol to ALT+F8), and now, I use it to make my MovieClip symbols.

if (fl.getDocumentDOM().selection.length > 0)
{
        mcName = prompt("MovieClip Name", "");
        if (mcName != null)
        {
                newMc = fl.getDocumentDOM().convertToSymbol("movie clip", mcName, "top left");
                fl.getDocumentDOM().selection[0].name = mcName;
        }
}

Posted in Flash, JSFL, Tips/Tricks

7 Responses

  1. jkozniewski

    Hi :)

    I've shared your pain till today :)
    so thanks for this little yet useful script. I've missed one feature though - setting of reg point other than "top left" so I've extended your jsfl ;)

    Now you can set reg point by just typing mcName*# into prompt where # is 1-9.
    Note that numbers are 'mapped' in a way that links numpad key layout directly with location of reg point. So for ex. 7 == "top left" and 5 == "center".

    You can download extended version here -> http://jkozniewski.com/tools/Convert%20to%20Symbol%20Ext.jsfl

  2. Steven Sacks

    I never set the registration point of a MovieClip to anything other than top left except in very specific edge cases. But, I'm glad you find the script helpful and your addition, too! :)

  3. Chad

    I had the same problem but tackled it a slightly different way. I created an AutoHotKey script to pop up an input window to enter the name. It doesn't auto-populate the name, but it is more efficient than jumping to the properties panel. Check out the info here:
    http://www.ultrashock.com/forums/flash-professional/jsfl-external-variable-clipboard-text-90632.html

  4. Danny

    You could always create your movie clips the "old fashioned" way and then create a JSFL script that names the instance(s) the same as the movie clip name(s) in the library:

    if (fl.getDocumentDOM().selection.length > 0)
    {

    for(i in fl.getDocumentDOM().selection){
    path = fl.getDocumentDOM().selection[i].libraryItem.name;
    mc_name = path.substr(path.lastIndexOf("/")+1);
    fl.trace('clip = '+mc_name);
    fl.getDocumentDOM().selection[i].name = mc_name;

    }

    }

  5. Steven Sacks

    That would take more time than it would for me to name it myself. One keyboard shortcut FTW! :)

  6. Guillermo

    ok so your piece of code is really helpful because it does the job, but what if you have 5 different movie clips and u want to give them instance names that are the same as what their are name as movie clips? u get it?

    5 movie clips distributed each in a layer…
    then give each movie clip an instance name

    any ideas?

    right now what your code does is give an instance name prompt it to the user but i have 5 movie clips and it only prompted me once?.. =/

    thanks

  7. Steven Sacks

    You have to iterate through the selection to get each MovieClip individually, or you're going to turn the selection into a symbol (it's exactly the same behavior as pressing F8, because Flash uses JSFL when you do).

Leave a Comment

Please note: Comment moderation is enabled and may delay your comment. There is no need to resubmit your comment.

About Steven Sacks

I am a professional Flash developer with over 13 years of programming experience. I have consulted for high-profile agencies and companies in San Francisco, Los Angeles, Atlanta and New York, and developed numerous award-winning websites and rich internet applications for clients including Adobe, Fox Sports, FX Networks, Anheuser-Busch, GE, DirecTV, ESPN, The Weather Channel, Home Depot, and Coca-Cola.

I am the author of the open-source Gaia Framework for Adobe Flash, which dramatically reduces development time and makes developing Flash sites much easier.