Using JSFL to auto-name instances of newly created MovieClips
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
February 2nd, 2008 at 2:52 am
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
February 2nd, 2008 at 3:29 am
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!
March 3rd, 2008 at 8:49 am
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
March 21st, 2008 at 11:02 pm
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;
}
}
March 24th, 2008 at 12:00 am
That would take more time than it would for me to name it myself. One keyboard shortcut FTW!
June 30th, 2008 at 11:04 am
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
July 2nd, 2008 at 11:03 am
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).
October 20th, 2008 at 10:24 am
[...] upon the previous post, one of the other things I do quite often is create MovieClip buttons using a little-known trick in [...]
April 9th, 2010 at 9:55 am
Thank you man.
July 23rd, 2010 at 2:25 pm
thanks for the post — Danny's comment just saved me hours and hours in importing AI files.
bril.