Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/actionscript-3/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Actionscript 3 如何跳转到下一帧actionscript 3_Actionscript 3 - Fatal编程技术网

Actionscript 3 如何跳转到下一帧actionscript 3

Actionscript 3 如何跳转到下一帧actionscript 3,actionscript-3,Actionscript 3,我这里有一个记忆游戏。每次从游戏板上取下一张牌,我就有“cardCount-2”,当这个cardCount为零时,我希望程序跳转到下一帧,就像一个“游戏结束”页面。我试过使用gotoAndStop();以及nextFrame();但它似乎不起作用 在我的第一帧我有游戏,在第二帧我有游戏结束页面 任何帮助都将不胜感激!谢谢大家! 这是我的密码 package { import flash.display.Sprite; import flash.events.MouseEvent; import

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

在我的第一帧我有游戏,在第二帧我有游戏结束页面

任何帮助都将不胜感激!谢谢大家!

这是我的密码

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

                }


}
包{
导入flash.display.Sprite;
导入flash.events.MouseEvent;
导入flash.events.TimerEvent;
导入flash.utils.Timer;
导入flash.display.MovieClip;
公共类MemoryGame扩展了Sprite{
私人瓷砖:卡片;
私人信用卡:信用卡;
专用变量pauseTimer:定时器;
专用变量levelTimer:定时器;
私人var评分:int;
私人var卡数:int;
var numberDeck:Array=新数组(1,1,2,2,3,3,4,4,5,5,6,6);
公共函数MemoryGame(){
得分=0;
text=“:”+分数;

对于(x=1;x如果帧位于主时间线上,则需要调用
stage.gotoAndStop(2)尝试从
MovieClip
扩展
MemoryGame
,而不是从
Sprite

扩展
MemoryGame
,我尝试了此操作并收到以下错误:通过静态类型flash的引用调用可能未定义的方法gotoAndStop。显示:StageI还尝试了event.target.parent.gotoAndStop(2)但它仍然不起作用!我收到“ReferenceError:Error#1069:Property parent未在flash.utils.Timer上找到,并且没有默认值。在flash.events::EventDispatcher/dispatchevenfunction()在flash.events::EventDispatcher/dispatchEvent()在flash.utils::Timer/tick()上”你能描述一下你是如何将MemoryGame精灵添加到舞台上的吗?
MemoryGame
是你的主类吗?是的!它都在上面的代码中。我的全部代码都在那里。你有没有尝试过
this.gotoAndStop(2);
when
if(cardCount==0){…}
?1061:通过静态类型MemoryGame的引用调用可能未定义的方法gotoAndStop。因此,核心问题是您的
MemoryGame
不是
MovieClip
类型。因此,您可以接受我的答案。请尝试
root.gotoAndStop(2);
MovieClip(此.父项)。gotoAndStop(2);
MovieClip(this.parent.parent).gotoAndStop(2);