0

我在库中有两个带有链接的电影剪辑。

在舞台上,我有两个按钮 - 每个按钮将影片剪辑加载到舞台上的特定 mc 目标。我还有第三个按钮可以删除 mc 目标,以清除舞台。

我想知道如何更改 AS3 中的代码,以便加载的影片剪辑不会同时显示,而是相互交换,就像我以前在 AS2 中使用深度一样。

这是代码:

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);
;   
}
4

1 回答 1

0

我会推荐这样的东西:

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;  
}

但是如果你真的想交换,你也可以执行以下操作,但是我建议设置可见标志,因为它更有效,而不是覆盖不需要绘制的东西。

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);
    }
}
于 2013-10-10T20:33:58.470 回答