简体   繁体   English

数组项目检查as3

[英]Array items check as3

I have 4 movieclips in an array 我在阵列中有4个电影剪辑

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

Inside each one there is code to vanish when it's clicked with the mouse on the second frame. 在每一个内部都有代码,当用鼠标在第二帧上单击时,该代码将消失。

this.visible = false;

From the main timeline is the control for the mouse click for each of the tiles (only the first one is displayed). 在主时间轴上是每个图块的鼠标单击控件(仅显示第一个图块)。

tile1.addEventListener(MouseEvent.CLICK, fl_);

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

How can I make it so when all the tiles in the array become invisible, flash to take action (such as to go to frame 5)? 当阵列中的所有图块都变得不可见时,如何闪烁以采取措施(例如转到第5帧),我该怎么做?

Thank you! 谢谢!

I've looked at your .fla. 我看过你的.fla。 Here are two ways to do what you'd like: 这是两种您想做的事:

On Your Main Timeline: (replace the current main timeline frame 1 code with the following) 在您的主要时间轴上:(用以下内容替换当前的主要时间轴第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);
}

If the above is intimidating and you would prefer to keep it like it was before, then this is all you'd have to do: (again, this code will replace your current main timeline frame 1 code) 如果上面的内容令人生畏,并且您希望像以前一样保留它,那么这就是您所要做的:(再次,此代码将替换当前的主时间轴第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);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM