错误1180,Flash

时间:2013-12-04 16:13:00

标签: actionscript-3 flash compiler-errors

所以,和上次一样的大学项目,这次我遇到了未定义方法的问题。我的代码的完整性在

之下
package 
{
import flash.display.MovieClip;
import flash.events.MouseEvent;
public class Lesson_05 extends MovieClip
{
    private static const boardWidth:uint = 4;
    private static const boardHeight:uint = 2;
    private static const cardHorizontalSpacing:Number = 52;
    private static const cardVerticalSpacing:Number = 52;
    private static const boardOffsetX:Number = 171;
    private static const boardOffsetY:Number = 148;
    private var firstCard:Card;
    private var secondCard:Card;
    private var cardsLeft:uint;
    var startPage:StartPage_1;
    var matchPage:MatchPage_1;
    var guessPage:GuessPage_1;
    var startMessage:String;
    var mysteryNumber:uint;
    var currentGuess:uint;
    var guessesRemaining:uint;
    var guessesMade:uint;
    var gameStatus:String;
    var gameWon:Boolean;

    public function Lesson_05():void
    {
        startPage = new StartPage_1();
        matchPage = new MatchPage_1();
        guessPage = new GuessPage_1();
        addChild(startPage);

        startPage.matchButton.addEventListener(MouseEvent.CLICK,onMatchButtonClick);
        startPage.guessButton_1.addEventListener(MouseEvent.CLICK,onGuessButtonClick_1);
        guessPage.matchButton.addEventListener(MouseEvent.CLICK,onMatchButtonClick_Guess);
        //Output Errors #2025 when added this line;
        guessPage.startButton.addEventListener(MouseEvent.CLICK,onStartButtonClick);
        matchPage.startButton.addEventListener(MouseEvent.CLICK,onStartButtonClick_Match);
        matchPage.guessButton_1.addEventListener(MouseEvent.CLICK,onGuessButtonClick_Match_1);
    }
    function onMatchButtonClick(event:MouseEvent):void
    {
        addChild(matchPage);
        removeChild(startPage);
        match();
    }
    function onGuessButtonClick_1(event:MouseEvent):void
    {
        addChild(guessPage);
        removeChild(startPage);
        guess();
    }
    function onMatchButtonClick_Guess(event:MouseEvent):void
    {
        addChild(matchPage);
        removeChild(guessPage);
        match();
    }
    function onStartButtonClick(event:MouseEvent):void
    {
        addChild(startPage);
        removeChild(guessPage);
    }
    function onStartButtonClick_Match(event:MouseEvent):void
    {
        addChild(startPage);
        removeChild(matchPage);
    }
    function onGuessButtonClick_Match_1(event:MouseEvent):void
    {
        addChild(guessPage);
        removeChild(matchPage);
        guess();
    }

    function guess():void
        {
            startMessage = "I am thinking of a number between 1 and 20";
            mysteryNumber = Math.ceil(Math.random()*20);
            guessesRemaining = 10;
            guessesMade = 0;
            gameStatus = "";
            gameWon = false;

            guessPage.output_txt.text = startMessage;
            guessPage.input_txt.text = "";
            guessPage.input_txt.backgroundColor = 0xFFCCCCCC;
            guessPage.input_txt.restrict = "0-9";
            guessPage.stage.focus = guessPage.input_txt;
            guessPage.guessButton_2.enabled = true;
            guessPage.guessButton_2.alpha = 1;
            guessPage.againButton_1.visible = false;
            guessPage.guessButton_2.addEventListener(MouseEvent.CLICK,onGuessButtonClick_2);
        }
        function onGuessButtonClick_2(event:MouseEvent):void
        {
            guessesRemaining--;
            guessesMade++;
            gameStatus = "Guesses Remaining: " + guessesRemaining + ", GuessesMade:" + guessesMade;
            currentGuess = uint(guessPage.input_txt.text);
            if (currentGuess > mysteryNumber)
            {
                guessPage.output_txt.text = "That's too high!" + "\n" + gameStatus;
                checkGameOver();
            }
            else if (currentGuess < mysteryNumber)
            {
                guessPage.output_txt.text = "That's too low!" + "\n" + gameStatus;
                checkGameOver();
            }
            else
            {
                //guessPage.output_txt.text = "Well Done! You got it!";
                gameWon = true;
                endGame();
            }
            function checkGameOver():void
            {
                if (guessesRemaining < 1)
                {
                    endGame();
                }
            }
            function endGame():void
            {
                if (gameWon)
                {
                    guessPage.output_txt.text = "Yes, it's " + mysteryNumber + "!" + "\n" + "It only took you " + guessesMade + " guesses!";
                }
                else
                {
                    guessPage.output_txt.text = "Sorry, you've run out of guesses!" + "\n" + "The correct number was " + mysteryNumber + ".";
                }
                guessPage.guessButton_2.removeEventListener(MouseEvent.CLICK,onGuessButtonClick_2);
                guessPage.guessButton_2.enabled = false;
                guessPage.guessButton_2.alpha = 0.5;
                guessPage.againButton_1.visible = true;
                guessPage.againButton_1.addEventListener(MouseEvent.CLICK,onAgainButtonClick_1);
            }
            function onAgainButtonClick_1(event:MouseEvent):void
            {
                guess();
                guessPage.againButton_1.removeEventListener(MouseEvent.CLICK,onAgainButtonClick_1);
            }

    function match():void
    {
        var cardlist:Array = new Array();
        for (var i:uint=0; i<boardWidth*boardHeight/2; i++)
        {
            cardlist.push(i);
            cardlist.push(i);
        }
        cardsLeft = 0;
        for (var x:uint=0; x<boardWidth; x++)
        {
            for (var y:uint=0; y<boardHeight; y++)
            {
                var c:Card = new Card();
                c.stop();
                c.x = x * cardHorizontalSpacing + boardOffsetX;
                c.y = y * cardVerticalSpacing + boardOffsetY;
                var r:uint = Math.floor(Math.random() * cardlist.length);
                c.cardface = cardlist[r];
                cardlist.splice(r,1);
                c.addEventListener(MouseEvent.CLICK,clickCard);
                addChild(c);
                cardsLeft++;
            }
        }
    }
    function clickCard(event:MouseEvent)
    {
        var thisCard:Card = (event.target as Card);

        if (firstCard ==null)
        {
            firstCard = thisCard;
            firstCard.gotoAndStop(thisCard.cardface+2);

        }
        else if (firstCard ==thisCard)
        {
            firstCard.gotoAndstop(1);
            firstCard = null;
        }
        else if (secondCard == null)
        {
            secondCard = thisCard;
            secondCard.gotoAndStop(thisCard.cardface+2);

            if (firstCard.cardface == secondCard.cardface)
            {
                removeChild(firstCard);
                removeChild(secondCard);

                firstCard = null;
                secondCard = null;
                cardsLeft -=  2;
                if (cardsLeft ==0)
                {
                }

            }
        }
        else
        {
            firstCard.gotoAndStop(1);
            secondCard.gotoAndStop(1);
            secondCard = null;
            firstCard = thisCard;
            firstCard.gotoAndStop(thisCard.cardface+2);
        }

        }
    }
}
}

我遇到的问题是: 1180:调用可能未定义的方法匹配。

我对AS3知之甚少,并且花了2个多小时试图解决这个问题。在此先感谢大家,PS任何指向教程的链接都非常受欢迎

3 个答案:

答案 0 :(得分:1)

你错放了函数 onGuessButtonClick_2 的紧密括号'}'。使用以下代码并进行检查。

package 
{
import flash.display.MovieClip;
import flash.events.MouseEvent;
public class Lesson_05 extends MovieClip
{
    private static const boardWidth:uint = 4;
    private static const boardHeight:uint = 2;
    private static const cardHorizontalSpacing:Number = 52;
    private static const cardVerticalSpacing:Number = 52;
    private static const boardOffsetX:Number = 171;
    private static const boardOffsetY:Number = 148;
    private var firstCard:Card;
    private var secondCard:Card;
    private var cardsLeft:uint;
    var startPage:StartPage_1;
    var matchPage:MatchPage_1;
    var guessPage:GuessPage_1;
    var startMessage:String;
    var mysteryNumber:uint;
    var currentGuess:uint;
    var guessesRemaining:uint;
    var guessesMade:uint;
    var gameStatus:String;
    var gameWon:Boolean;

    public function Lesson_05():void
    {
        startPage = new StartPage_1();
        matchPage = new MatchPage_1();
        guessPage = new GuessPage_1();
        addChild(startPage);

        startPage.matchButton.addEventListener(MouseEvent.CLICK,onMatchButtonClick);
        startPage.guessButton_1.addEventListener(MouseEvent.CLICK,onGuessButtonClick_1);
        guessPage.matchButton.addEventListener(MouseEvent.CLICK,onMatchButtonClick_Guess);
        //Output Errors #2025 when added this line;
        guessPage.startButton.addEventListener(MouseEvent.CLICK,onStartButtonClick);
        matchPage.startButton.addEventListener(MouseEvent.CLICK,onStartButtonClick_Match);
        matchPage.guessButton_1.addEventListener(MouseEvent.CLICK,onGuessButtonClick_Match_1);
    }
    function onMatchButtonClick(event:MouseEvent):void
    {
        addChild(matchPage);
        removeChild(startPage);
        match();
    }
    function onGuessButtonClick_1(event:MouseEvent):void
    {
        addChild(guessPage);
        removeChild(startPage);
        guess();
    }
    function onMatchButtonClick_Guess(event:MouseEvent):void
    {
        addChild(matchPage);
        removeChild(guessPage);
        match();
    }
    function onStartButtonClick(event:MouseEvent):void
    {
        addChild(startPage);
        removeChild(guessPage);
    }
    function onStartButtonClick_Match(event:MouseEvent):void
    {
        addChild(startPage);
        removeChild(matchPage);
    }
    function onGuessButtonClick_Match_1(event:MouseEvent):void
    {
        addChild(guessPage);
        removeChild(matchPage);
        guess();
    }

    function guess():void
        {
            startMessage = "I am thinking of a number between 1 and 20";
            mysteryNumber = Math.ceil(Math.random()*20);
            guessesRemaining = 10;
            guessesMade = 0;
            gameStatus = "";
            gameWon = false;

            guessPage.output_txt.text = startMessage;
            guessPage.input_txt.text = "";
            guessPage.input_txt.backgroundColor = 0xFFCCCCCC;
            guessPage.input_txt.restrict = "0-9";
            guessPage.stage.focus = guessPage.input_txt;
            guessPage.guessButton_2.enabled = true;
            guessPage.guessButton_2.alpha = 1;
            guessPage.againButton_1.visible = false;
            guessPage.guessButton_2.addEventListener(MouseEvent.CLICK,onGuessButtonClick_2);
        }
        function onGuessButtonClick_2(event:MouseEvent):void
        {
            guessesRemaining--;
            guessesMade++;
            gameStatus = "Guesses Remaining: " + guessesRemaining + ", GuessesMade:" + guessesMade;
            currentGuess = uint(guessPage.input_txt.text);
            if (currentGuess > mysteryNumber)
            {
                guessPage.output_txt.text = "That's too high!" + "\n" + gameStatus;
                checkGameOver();
            }
            else if (currentGuess < mysteryNumber)
            {
                guessPage.output_txt.text = "That's too low!" + "\n" + gameStatus;
                checkGameOver();
            }
            else
            {
                //guessPage.output_txt.text = "Well Done! You got it!";
                gameWon = true;
                endGame();
            }
        }
        function checkGameOver():void
            {
                if (guessesRemaining < 1)
                {
                    endGame();
                }
            }
        function endGame():void
            {
                if (gameWon)
                {
                    guessPage.output_txt.text = "Yes, it's " + mysteryNumber + "!" + "\n" + "It only took you " + guessesMade + " guesses!";
                }
                else
                {
                    guessPage.output_txt.text = "Sorry, you've run out of guesses!" + "\n" + "The correct number was " + mysteryNumber + ".";
                }
                guessPage.guessButton_2.removeEventListener(MouseEvent.CLICK,onGuessButtonClick_2);
                guessPage.guessButton_2.enabled = false;
                guessPage.guessButton_2.alpha = 0.5;
                guessPage.againButton_1.visible = true;
                guessPage.againButton_1.addEventListener(MouseEvent.CLICK,onAgainButtonClick_1);
            }
         function onAgainButtonClick_1(event:MouseEvent):void
            {
                guess();
                guessPage.againButton_1.removeEventListener(MouseEvent.CLICK,onAgainButtonClick_1);
            }

    function match():void
    {
        var cardlist:Array = new Array();
        for (var i:uint=0; i<boardWidth*boardHeight/2; i++)
        {
            cardlist.push(i);
            cardlist.push(i);
        }
        cardsLeft = 0;
        for (var x:uint=0; x<boardWidth; x++)
        {
            for (var y:uint=0; y<boardHeight; y++)
            {
                var c:Card = new Card();
                c.stop();
                c.x = x * cardHorizontalSpacing + boardOffsetX;
                c.y = y * cardVerticalSpacing + boardOffsetY;
                var r:uint = Math.floor(Math.random() * cardlist.length);
                c.cardface = cardlist[r];
                cardlist.splice(r,1);
                c.addEventListener(MouseEvent.CLICK,clickCard);
                addChild(c);
                cardsLeft++;
            }
        }
    }
    function clickCard(event:MouseEvent)
    {
        var thisCard:Card = (event.target as Card);

        if (firstCard ==null)
        {
            firstCard = thisCard;
            firstCard.gotoAndStop(thisCard.cardface+2);

        }
        else if (firstCard ==thisCard)
        {
            firstCard.gotoAndstop(1);
            firstCard = null;
        }
        else if (secondCard == null)
        {
            secondCard = thisCard;
            secondCard.gotoAndStop(thisCard.cardface+2);

            if (firstCard.cardface == secondCard.cardface)
            {
                removeChild(firstCard);
                removeChild(secondCard);

                firstCard = null;
                secondCard = null;
                cardsLeft -=  2;
                if (cardsLeft ==0)
                {
                }

            }
        }
        else
        {
            firstCard.gotoAndStop(1);
            secondCard.gotoAndStop(1);
            secondCard = null;
            firstCard = thisCard;
            firstCard.gotoAndStop(thisCard.cardface+2);
        }


    }
}
}

希望它有所帮助。

答案 1 :(得分:1)

您的match()函数位于onGuessButtonClick_2(MouseEvent)函数内。

所以当你从其他不在onGuessButtonClick_2函数内部的地方尝试时,flash会因为无法找到函数match()而感到困惑,因为它只能在{{1}内调用功能。

答案 2 :(得分:0)

1180错误是由Flash死机造成的。

1180 Error: Flash is Dead, please convert your code to HTML5 or do it natively. 
okthxbai     
Adobe