0
votes

I have several movie clips into a frame the size of the stage and I have to switch through a button between those pages.

So if I press button, should all the other frames removeChild and the one where he is called to go addChild.

Edit: I have the actionscript placed in the timeline of the movieClip so the button is not on the stage but I put in the movie clip using action script.

So what DodgerThud showed here is not possible because the button has changed since that is in the movieClip('s).

I think I need to place the same code in every movieClip.

2

2 Answers

0
votes

Put all of your MovieClips into a Vector or Array.

When you click the button, you should cycle through the Vector/Array and check if the MovieClip is currently on stage with contains(DisplayObject). If the Movieclip IS currently on the stage, remove it and add another one to the stage, for example, the next one in the Vector/Array.

var vec:Vector.<MovieClip> = new Vector.<MovieClip>
vec[0] = new MovieClip();
vec[1] = new MovieClip();  //example with MovieClips
vec[2] = new MovieClip();

addChild(vec[0]);  //add one of the MovieClips to stage

button.addEventListener(MouseEvent.CLICK, onClick);

function onClick(e:MouseEvent):void
{
    for(var i:int = 0; i < vec.length; i++) //go through the Vector one by one
    {
         if(contains(vec[i])  //if the Object at position i in the Vector is on stage
         {
              removeChild(vec[i]); //remove the Object
              var next:int = i;    //create a temporary holder
              if(next == vec.length) //check if the displayed Object was the last in the list
              {
                   next = 0;  //if so, set to 0
              }else{
                   next++; //otherwise, only add 1
              }
              addChild(vec[next]); //add the next Object to the stage. If the removed Object was the last in the Vector, it'll add the first Object in the Vector to the list
              break; //escape the for loop, otherwise it'll always only show the last Object
         }

    }
}
0
votes

Something like ...

function tueHandler(e:MouseEvent):void
{
  while(numChildren > 0)
    removeChildAt(0);
  addChild(whatever);
}