1
votes

So I have 5 movieclips on screen that when clicked (DOWN state) expand. They all come to the top of the screen because of this code:

addChildAt(this.Step0btn,1);
addChildAt(this.Step1btn,1);
addChildAt(this.Step2btn,1);
addChildAt(this.Step3btn,1);
addChildAt(this.Step4btn,1);

My issue is that on each of the expanded movieclips is another movieclip that also expands, but when I click that it still displays underneath everything else. I thought I could just add another addChildAt command like:

addChildAt(this.Step0btn.Step0img,1);

But when I do that I get this error:

TypeError: Error #2007: Parameter child must be non-null. at flash.display::DisplayObjectContainer/addChildAt() at SMARTTTraining_fla::MainTimeline/SMARTTTraining_fla::frame5()[SMARTTTraining_fla.MainTimeline::frame5:14]

And then the expanded movieclip still displays underneath everything. What could be wrong here?

1

1 Answers

2
votes

Step0img is null when that line of code runs. Likely explaination could be that Step0img doesn't exist on the frame that Step0Btn is on.

For your layering issue (and your error I suppose too), this would be what you'd want to do:

this.addChild(Step0btn);  

OR

this.setChildIndex(Step0btn,this.numChildren-1);

They do the same thing. This will bring to the foremost layer above the other step buttons, you don't want to change parent/child relationship by doing addChild(step0btn.step0img);

If you are using the same code that I provided in your other question, this is what the onPress method would look like now:

function onPress(event:MouseEvent):void
{
    // toggle between frame 1 and 3 on button press
    gotoAndStop(Step0btn.currentFrame == 3 ? 1 : 3); //this expands your button presumably
    parent.addChild(this); //moves this (this button) to the foreground  
}