2
votes

I'm trying to hide movie clips from the stage using a loop, but I'm getting the following error when I publish it (this is just an example of the concept.)

var q;
for (q = 0; q <= 3; q++) {
   stage["box_mc_" + q].visible = false;
}

The Error message:

ReferenceError: Error #1069: Property box_mc_0 not found on flash.display.Stage and there is no default value. at test_fla::MainTimeline/frame1()

ReferenceError: Error #1069: Property box_mc_0 not found on flash.display.Stage and there is no default value. at test_fla::MainTimeline/frame1()

Any help would be appreciated.

2

2 Answers

3
votes

You simply need to use the this keyword instead of the stage variable:

var q;
for (q = 1; q <= 3; q++) {
   this["box_mc_" + q].visible = false;
}

The simple reason being is that the objects are the children of a MainTimeline object, to which the this keyword would refer to in that context, and they are not the direct children of the stage.
If you're interested for more details on the difference, you may find useful information here.

1
votes

thats not realy child of stage,

if you try it, to tracing all of the stage childs

for (var i:int =0; i<stage.numChildren; i++) {
    trace(stage.getChildAt(i).name);
}

then you can see an intermediate container exists between stage and box_mc_# that's "root", because you added box_mc_# via time line

so in my case, the correct call way is

var q;
for (q = 0; q <= 3; q++) {
   stage.getChildByName("root1")["box_mc_" + q].visible = false;
}