0
votes

I have two movie clips in the library with linkage.

on the stage I have two buttons - each load a movie clip to a specific mc target on the stage. I also have a third button that removes the mc target, to clear the stage.

I want to know how can I change the code in AS3 so the loaded movie clips will not show at the same time, but swap each other, like I used to use depth in AS2.

This is the code:

var myIgool = new igool ();
var myRibooa = new ribooa ();

loadigool.addEventListener(MouseEvent.CLICK, fl_MouseClickHandler_3);


function fl_MouseClickHandler_3(event:MouseEvent):void
{
mc_all.addChild (myIgool);
}

loadribooa.addEventListener(MouseEvent.CLICK, fl_MouseClickHandler_4);

function fl_MouseClickHandler_4(event:MouseEvent):void
{
mc_all.addChild (myRibooa);
}


unloadall.addEventListener(MouseEvent.CLICK, fl_MouseClickHandler_6);

function fl_MouseClickHandler_6(event:MouseEvent):void
{
removeChild(mc_all);
;   
}
1

1 Answers

0
votes

I would recommend something like this:

var myIgool = new igool ();
var myRibooa = new ribooa ();

mc_all.addChild(myIgool);
mc_all.addChild(myRibooa);

myIgool.visible = false;
myRibooa.visible = false;

loadigool.addEventListener(MouseEvent.CLICK, fl_MouseClickHandler_3);

function fl_MouseClickHandler_3(event:MouseEvent):void
{
    myIgool.visible = true;
    myRibooa.visible = false;
}

loadribooa.addEventListener(MouseEvent.CLICK, fl_MouseClickHandler_4);

function fl_MouseClickHandler_4(event:MouseEvent):void
{
    myIgool.visible = false;
    myRibooa.visible = true;
}

unloadall.addEventListener(MouseEvent.CLICK, fl_MouseClickHandler_6);

function fl_MouseClickHandler_6(event:MouseEvent):void
{
    myIgool.visible = false;
    myRibooa.visible = false;  
}

But if you really want to swap, you could also do the following, however I recommend setting the visible flag as it's more efficient rather than covering something up that wouldn't need to draw.

loadigool.addEventListener(MouseEvent.CLICK, fl_MouseClickHandler_3);

function fl_MouseClickHandler_3(event:MouseEvent):void
{
    if (myIgool.parent != mc_all)
    {
        mc_all.addChild(myIgool);
    }
    else
    {
        mc_all.setChildIndex(myIgool, mc_all.numChildren - 1);
    }
}

loadribooa.addEventListener(MouseEvent.CLICK, fl_MouseClickHandler_4);

function fl_MouseClickHandler_4(event:MouseEvent):void
{
    if (myRibooa.parent != mc_all)
    {
        mc_all.addChild(myRibooa);
    }
    else
    {
        mc_all.setChildIndex(myRibooa, mc_all.numChildren - 1);
    }
}