我试图创建一个简单的记忆游戏我有3帧简介,主游戏,结束然而每次我点击“开始按钮”跳转到第2帧我不断收到此错误;
TypeError: Error #1006: Play_AnimalCardGame is not a function.
at AnimalCardGame/frame2()
at flash.display::MovieClip/gotoAndStop()
at AnimalCardGame/startGame()
我的.AS
package{
import flash.display.*;
import flash.events.*;
import flash.utils.getTimer;
public class Play_AnimalCardGame extends MovieClip
{
private static const boardWidth:uint =4;
private static const boardHeight:uint =3;
private static const cardVSpace:Number=100;
private static const cardHSpace:Number=15;
private static const offSetX:Number=115;
private static const offSetY:Number=155;
public function Play_AnimalCardGame ():void
{
var cardDeck:Array = new Array();
for ( var i:uint=0;i<boardWidth*boardHeight/2;i++){
cardDeck.push(i);
cardDeck.push(i);
}
for(var x:uint=0; x<boardWidth ; x++){
for(var y:uint=0; y<boardHeight;y++){
var aCard:Card = new Card();
aCard.stop();
aCard.x = x*offSetX+cardVSpace;
aCard.y = y*offSetY+cardHSpace;
var randomCard:uint = Math.floor(Math.random()*cardDeck.length);
aCard.cardface= cardDeck[randomCard];
cardDeck.splice(randomCard,1);
aCard.gotoAndStop(1);
aCard.addEventListener(MouseEvent.CLICK,clickCard);
addChild(aCard);
cardLeft++;
}
}
}
private var firstPick:Card;
private var secondPick:Card;
private var cardLeft;
private static const pointHit:int =100;
private static const pointMiss:int = -5;
private var startscore =0;
var startTime:uint;
var time:uint;
public function clickCard(event:MouseEvent){
var pickedCard:Card = (event.currentTarget as Card);
if(firstPick == null){
firstPick =pickedCard;
firstPick.gotoAndStop(pickedCard.cardface+2);
}
else if (firstPick ==pickedCard){
firstPick.gotoAndStop(1);
firstPick=null;
}
else if (secondPick ==null){
secondPick= pickedCard;
secondPick.gotoAndStop(pickedCard.cardface+2);
if (firstPick.cardface == secondPick.cardface){
startscore +=pointHit;
cardLeft-=2;
removeChild(firstPick);
removeChild(secondPick);
txtscore.text= String(startscore);
firstPick = null;
secondPick=null;
}
else{
firstPick.gotoAndStop(1);
secondPick.gotoAndStop(1);
startscore +=pointMiss;
txtscore.text= String(startscore);
secondPick=null;
firstPick = pickedCard;
firstPick.gotoAndStop(pickedCard.cardface+2);
}
}
if(cardLeft==0){
gotoAndStop("gameover");
}
}
public function showTimer(event:Event)
{
startTime = getTimer();
time=0;
time = getTimer()- startTime;
txtTime.text = clockTime(time);
}
public function clockTime(ms:int){
var seconds:int = Math.floor(ms/1000);
var minutes:int = Math.floor(seconds/60);
seconds -=minutes *60;
var timeString:String = minutes+":"+String(seconds+100).substr(1,2);
return timeString;
}
}
从我能做到的事情没有问题但是又一次只能学习
答案 0 :(得分:1)
看起来您已将类名定义为
Play_AnimalCardGame
但是你将构造函数定义为
AnimalCardGame
首先将构造函数名称设置为与类名称相同