2014-09-25 57 views
0

我有4點的movieclip以陣列數組項檢查AS3

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)?

謝謝!

回答

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); 
} 
+0

非常感謝您的回答,我只是問,如何c我在不改變當前配置的情況下轉到第5幀。它必須進入瓦片內的第2幀,這些瓦片實際上在容器MC內。我希望從這裏的答案我會找出其餘的,但現在它變得更加困難,無論如何謝謝。順便提一下下面的文件:https://app.box.com/files/0/f/0/1/f_21071986269 – Johnnien 2014-09-26 19:15:47

+1

我不確定你還想做什麼?製作被點擊的圖塊到第2幀是很容易的(我更新了答案),還有什麼難處? – BadFeelingAboutThis 2014-09-26 19:41:41

+0

我有tile.visible = false;在瓷磚內的第二個框架上。要去那個框架2我有cont.tile1.addEventListener(MouseEvent.CLICK,fl_); function fl_(event:MouseEvent):void { tile1.gotoAndStop(2); }而且就像我有mc裏面有4個瓷磚叫做「cont」。一旦它們全部被點擊並且不可見,我需要採取行動,例如在主時間軸上轉到第5幀。就這些!我不確定是否需要數組。謝謝。 – Johnnien 2014-09-27 21:15:14