数组项检查为3

时间:2014-09-25 21:51:09

标签: actionscript-3 flash onclick visible

我在一个数组中有4个动画片段

var tiles:Array = new Array("tile1","tile2","tile3","tile4");

在每一个内部都有代码在第二帧用鼠标点击时消失。

this.visible = false;

从主时间轴开始,每个图块的鼠标单击控件(仅显示第一个图块)。

tile1.addEventListener(MouseEvent.CLICK, fl_);

function fl_(event:MouseEvent):void
{
    tile1.gotoAndStop(2);
}

当阵列中的所有图块变得不可见时,如何进行操作(例如转到第5帧),我该怎么做呢?

谢谢!

1 个答案:

答案 0 :(得分:2)

我看了你的.fla。以下是两种方法:

在主时间轴上:(用以下内容替换当前主时间轴第1帧代码)

stop(); 

//loop through every child of the `cont` container, and add the same click listener
var i:int = cont.numChildren
while(i--){
    var tile:MovieClip = cont.getChildAt(i) as MovieClip;
    if(tile){
       tile.addEventListener(MouseEvent.CLICK, tileClick, false,0,true);
    }
}

function tileClick(e:MouseEvent):void {
    //this gets a reference to one that was clicked
    var tile:MovieClip = e.currentTarget as MovieClip;

    tile.gotoAndStop(2);

    //loop through the tile array to see if any are still visible
    var i:int = cont.numChildren
    while(i--){
        tile = cont.getChildAt(i) as MovieClip;
        if(tile && tile.currentFrame == 1) return;
    }

    //if we got this far, all the tiles are hidden, lets go to frame 5.
    gotoAndStop(5);
}

如果上述情况令人生畏,您希望保持原样,那么这就是您必须做的事情:(再次,此代码将替换您当前的主时间轴第1帧代码)

stop();

cont.tile1.addEventListener(MouseEvent.CLICK, tileClick);
cont.tile2.addEventListener(MouseEvent.CLICK, tileClick);
cont.tile3.addEventListener(MouseEvent.CLICK, tileClick);
cont.tile4.addEventListener(MouseEvent.CLICK, tileClick);

function tileClick(e:MouseEvent):void {
    MovieClip(e.currentTarget).gotoAndStop(2);
    if(cont.tile1.currentFrame == 1) return;
    if(cont.tile2.currentFrame == 1) return;
    if(cont.tile3.currentFrame == 1) return;
    if(cont.tile4.currentFrame == 1) return;

    //if we got this far, all the tiles are hidden, lets go to frame 5.
    gotoAndStop(5);
}