the idea is to access MC's on the stage with sequantial instance names, for example: mc1, mc2, mc3 ...
now, in as2 i would do: this["mc" + i] (where "i" represents a number between 1-3)
how would i do such thing in as3?
thanks in advance
the idea is to access MC's on the stage with sequantial instance names, for example: mc1, mc2, mc3 ...
now, in as2 i would do: this["mc" + i] (where "i" represents a number between 1-3)
how would i do such thing in as3?
thanks in advance
Hi,
If mc1,mc2,mc3 are located on the top level of your fla, and there are no other clips bellow them ( e.g. mc1 has has depth(index) 1, mc2 has index 2, etc. ) you could get the clips using getChildAt();
for(var i:int = 1 ; i < 3 ; i++){
var clip:MovieClip = MovieClip(getChildAt(i));
}
if you're not sure about depth management, just name your clips ( if they're on stage, give them instance names, if they're created at runtime, use the name property (mc1.name = 'mc1'))
and use getChildByName() to get them
for(var i:int = 1 ; i < 3 ; i++){
var clip:MovieClip = MovieClip(getChildByName('mc'+i));
trace(' got clip named: ' + clip.name);
}
I'm sure there a lot of resouces if you just google as2 as3 migration
this is not so tremendously simply anymore, as in AS2 ... you have to use DisplayObjectContainer::getChildByName
, so something like
for (var i:int = 1; i < 4; i++) {
trace(this.getChildByName("mc"+i));
}
good luck then ... ;)
this["mc" + i] works for me.
I made three MovieClips named mc1, mc2, and mc3, and placed them at x = 100, 200, and 300.
for (var i:int = 1; i <= 3; ++i) {
var mymc:MovieClip = this["mc" + i];
trace(mymc + ".x = " + mymc.x)
}
prints out
[object MovieClip].x = 100
[object MovieClip].x = 200
[object MovieClip].x = 300
since i can't mark all of your comments as "answered" i write this comment: All of your comments were helpful :) thanks!
this["mc" + i]
will work if mc1
is an instance variable of the class to which this
object belong to. The square bracket syntax can be used instead of the dot syntax in AS3 (though it is not recommended as it will turn compiler errors into runtime errors).
The following statements are equivalent:
this.mc1.width = 100;
this["mc1"].width = 100;