all groups > flash actionscript > october 2006 >
You're in the

flash actionscript

group:

return MovieClip symbol name from an instance


return MovieClip symbol name from an instance adam NO[at]SPAM blueapplestudio
10/11/2006 9:04:42 PM
flash actionscript:
I have variables that return _level0.mcContainer.mcSquare,
_level0.mcContainer.mcTriangle, etc. They are instances of the MovieClips
mcSquare, mcTriangle, etc.

Is there any way to take the variables and return the name of the MovieClip as
it appears in the Library?

Any assistance is appreciated.
Re: return MovieClip symbol name from an instance coldMiner
10/11/2006 9:36:12 PM
something like this:


var main:MovieClip = this.createEmptyMovieClip("main",
this.getNextHighestDepth());
// important to give it the same name if you plan to use the _name var:
var att1:MovieClip = main.attachMovie("mcSquare",
"mcSquare",main.getNextHighestDepth());
trace("MC: "+att1);
trace("Name: "+att1._name);
Re: return MovieClip symbol name from an instance adam NO[at]SPAM blueapplestudio
10/11/2006 9:54:33 PM
Thanks for the fast response. Very close to what I need, but I think that that
is returning the instance name still, and not the symbol name. A better
example for me to offer would be the below one.

There are variables that return _level0.mcContainer.mcSquare01, and
_level0.mcContainer.mcSquare02. These are both instances of the mcSquare
MovieClip, that were given dynamic instance names when they were created.

Using ._name returns mcSquare01 and mcSquare02. Is there a way to get
mcSquare out of it? A custom class is the only thing I can think of, just
wondering if there were a simpler solution.
Re: return MovieClip symbol name from an instance coldMiner
10/11/2006 11:21:07 PM
why not:


var main:MovieClip = this.createEmptyMovieClip("main",
this.getNextHighestDepth());
// important to give it the same name if you plan to use the _name var:
var att1:MovieClip = main.attachMovie("mcSquare",
"mcSquare01",main.getNextHighestDepth());
att1.attachName = "mcSquare"; // new
trace("MC: "+att1);
trace("Name: "+att1._name);
trace("Name: "+att1.attachName); // new
Re: return MovieClip symbol name from an instance adam NO[at]SPAM blueapplestudio
10/12/2006 3:08:21 PM
Thanks coldMiner, that code works very well.

AddThis Social Bookmark Button