gpt4 book ai didi

actionscript-3 - 错误1180,闪存

转载 作者:行者123 更新时间:2023-12-02 10:51:52 26 4
gpt4 key购买 nike

因此,与上一次相同的大学项目,这一次我遇到了未定义方法的麻烦。我的代码的完整性如下

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非常感谢教程的任何链接

最佳答案

您在GuessButtonClick_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);
}


}
}
}

希望能帮助到你。

关于actionscript-3 - 错误1180,闪存,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20380336/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com