如何跳转到下一帧动作3

时间:2012-03-18 06:53:24

标签: actionscript-3

我这里有记忆游戏。每次从游戏牌上移除一张卡片时我都会有“cardCount -2”,当这张cardCount变为零时,我希望程序跳转到下一帧,就像一个“游戏结束”页面。我尝试过使用gotoAndStop();以及nextFrame();但它似乎没有起作用!

在我的框架1上我有游戏,在第2帧我有游戏页面。

任何帮助都会非常感激!谢谢!

这是我的代码!

package {
import flash.display.Sprite;
import flash.events.MouseEvent;
import flash.events.TimerEvent;
import flash.utils.Timer;
import flash.display.MovieClip;

public class MemoryGame extends Sprite{

    private var firstTile:cards;
    private var secondTile:cards;
    private var pauseTimer:Timer;
    private var levelTimer:Timer;
    private var score:int;
    private var cardCount:int;




    var numberDeck:Array = new Array(1,1,2,2,3,3,4,4,5,5,6,6);


    public function MemoryGame(){
        score = 0;
        txtScore.text=": "+score;


        for(x=1; x<=4; x++) {
            for (y=1; y<=3; y++){
                var randomCard = Math.floor(Math.random()*numberDeck.length);
                var tile:cards = new cards();
                tile.card = numberDeck[randomCard];
                numberDeck.splice(randomCard,1);
                tile.gotoAndStop(9);
                tile.x = (x-1) * 150;
                tile.y = (y-1) * 200;
                tile.addEventListener(MouseEvent.CLICK,tileClicked);
                addChild(tile);
                cardCount = cardCount + 1

                if (cardCount == 0){
            trace("GAME OVER!")
            trace("SCORE:" +score);
        }


            }
        }
        trace("Cardcount: "+cardCount);
    }

    public function tileClicked(event:MouseEvent) {
        var clicked:cards = (event.currentTarget as cards);
        if (firstTile == null){
            firstTile = clicked;
            firstTile.gotoAndStop(clicked.card);
        }
        else if (secondTile == null && firstTile != clicked){
            secondTile = clicked;
            secondTile.gotoAndStop(clicked.card);
            if (firstTile.card == secondTile.card){
                pauseTimer = new Timer(1000, 1);
                pauseTimer.addEventListener(TimerEvent.TIMER_COMPLETE,removeCards);
                pauseTimer.start();

            }
            else {
                pauseTimer = new Timer(1000, 1);
                pauseTimer.addEventListener(TimerEvent.TIMER_COMPLETE,resetCards);
                pauseTimer.start();
            }
        }

    }

    public function resetCards(event:TimerEvent) {

        firstTile.gotoAndStop(9);
        secondTile.gotoAndStop(9);
        firstTile = null;
        secondTile = null;
        pauseTimer.removeEventListener(TimerEvent.TIMER_COMPLETE,resetCards);
        score = score - 2;
        txtScore.text=": "+score;
    }

    public function removeCards(event:TimerEvent){

        removeChild(firstTile);
        removeChild(secondTile);
        firstTile = null;
        secondTile = null;
        pauseTimer.removeEventListener(TimerEvent.TIMER_COMPLETE,removeCards);
        score = score + 10;
        txtScore.text=": "+score;
        cardCount = cardCount - 2;
        trace("Cardcount: " + cardCount);

        if (cardCount == 0){
            //NEXT FRAME CODE HERE!
            trace("GAME OVER!")
            trace("SCORE:" +score);
        }

                }


}

}

2 个答案:

答案 0 :(得分:1)

尝试从MemoryGame扩展MovieClip,而不是Sprite

答案 1 :(得分:0)

如果您的相框位于主时间轴上,则需要拨打stage.gotoAndStop(2);