Reputation: 722
hi I have a MovieClip, that I'm going to add to the display list with my document class at runtime beacuase there will be many instances of it. The MoviClip "box" has 3 more MovieClip instances inside it, and each of those three have two more. It looks like this:
box
circle 0
oval0
oval1
circle 1
oval0
oval1
circle 2
oval0
oval1
Here is the code I have right now:
package
{
import flash.display.MovieClip;
public class BoxSet extends MovieClip
{
private var theArr:Array;
public function BoxSet()
{
run();
}
private function run():void
{
theArr = new Array();
for (var i:uint = 0; i<this.numChildren; i++)
{
var mc:MovieClip = this["n" + i] as MovieClip;
addChild(mc);
theArr[i] = mc;
mc.alpha = 0;
}
}
public function setAlpha(num:uint):void
{
theArr[num].alpha = 1;
}
}
}
It's working but I want to know if there is a more efficient way of doing this, or if what I have is a good way of doing it? Any help will be appreciated.
Upvotes: 0
Views: 1149
Reputation: 1243
What you have looks perfectly efficient as long as you just want to reference the MovieClip instances by number and not by name.
Upvotes: 1
Reputation: 96
There are 2 ways for working with nested mcs in as3.0
1.absolute referencing (Rigid) 2. Relative referencing(Flexible).
In the structure, of nested mcs like mc3-> nested in mc2->nested in mc1
absolute refrcing will look like e.g. root.mc1.mc2.mc3 to access mc3 frm the main timeline
Relative referencing - at any stage you can refere to the parent of the mc using
this.parent
or any other mcs by extentending the abv structure.
sry 4 typos i m in a bit hurry
Upvotes: 0