我正在使用Adobe Animate CC为我们的论文创建一个Android游戏,每次我测试我的工作时,一开始它工作正常,但是当我去主游戏时,那里有一个出现错误:
Error #1010: A term is undefined and has no properties at RECOVER_RECOVER_dmthesis_demo_ver__paggumanarename_Scene14_fla::MainTimeline/frame1()[RECOVER_RECOVER_dmthesis_demo_ver__paggumanarename_Scene14_fla.MainTimeline::frame1:160]
这是我的代码(包括注释代码):
import flash.events.MouseEvent;
import flash.display.MovieClip;
import flash.events.Event;
import flash.display.Stage;
import flash.utils.Timer;
gril.gotoAndStop('a');
var gril:MovieClip = new MovieClip;
var linya:MovieClip = new MovieClip;
var timer:MovieClip = new MovieClip;
var scorer:MovieClip = new MovieClip;
var xDistance:Number
var yDistance:Number
var fl_SecondsToCountDown:Number = 5;
var fl_CountDownTimerInstance:Timer = new Timer(1000, fl_SecondsToCountDown);
var vx:Number = 5;
var vy:Number = 5;
var bg:MovieClip = new MovieClip;
var bg2:MovieClip = new MovieClip;
var qnaWin:MovieClip = new MovieClip;
var corekWin:MovieClip = new MovieClip;
var maliWin:MovieClip = new MovieClip;
var gameOverWin:MovieClip = new MovieClip;
//var btnPause:Button = new Button;
//var forward:Button = new Button;
bg.visible = true;
bg2.visible = false;
gril.visible = true;
linya.visible = true;
btnPause.visible = true;
pauseWin.visible = false;
qnaWin.visible = false;
corekWin.visible = false;
maliWin.visible = false;
scorer.visible = false;
timer.visible = false;
forward.visible = true;
gameOverWin.visible = false;
//var rightpressed:Boolean = new Boolean(false);
//var leftPressed:Boolean = new Boolean(false);
//var linkspeed:Number = 10;
//var contactApak: Boolean =false;
/*else if(keyEvent.keyCode == Keyboard.LEFT){
leftpressed = true;
}*/
//forward.enabled = true;
forward.addEventListener(MouseEvent.CLICK, myClickReaction);
// speeds ALONG NYPOTENUSE
function myClickReaction (e:MouseEvent):void {
vx = mouseX - gril.x;
vy = mouseY - gril.y;
addEventListener(Event.ENTER_FRAME, onEnterFrame);
gril.x+=10;
gril.gotoAndStop('i');
}
/*stage.addEventListener(MouseEvent.CLICK, keyDownHandler);
function keyDownHandler(event:MouseEvent):void{
if(event == Keyboard.RIGHT){
rightpressed = true;
}
}*/
function onEnterFrame(event:Event):void {
//mc increments by 5 until it reaches mouse - mc (ie the distance)
gril.x += vx;
gril.y += vy;
xDistance = Math.abs(mouseX - gril.x);
yDistance = Math.abs(mouseY - gril.y);
trace (xDistance)
if (xDistance == 0 ) {
removeEventListener(Event.ENTER_FRAME, onEnterFrame);
}
}
/*forward.addEventListener(MouseEvent.CLICK, lakad);
function lakad(event:MouseEvent):void{
if(event.keyCode == Keyboard.RIGHT){
rightpressed = false;
gril.gotoAndStop('a');
}
}*/
/*else if(keyEvent.keyCode == Keyboard.LEFT){
leftpressed = false;
mcgril.gotoAndStop("Stand Left Frame");
}*/
/*stage.addEventListener(Event.ENTER_FRAME, gameLoopi);
forward.addEventListener(MouseEvent.CLICK, gameLoopi);
function gameLoopi(e:Event):void{
gril.x+=10;
gril.gotoAndStop('i');
}*/
/*else if(leftpressed){
linkMC.x-=linkspeed;
linkMC.gotoAndStop("Walk Left Frame);
}*/
if(linya.hitTestObject(gril)){
qnaWin.visible = true;
}
/*if(apak.hitTestPoint(mcgril.x,mcgril.y+15,true)){
contactApak=true;
}
else{
contactApak=false;
}}*/
//btnPause.enabled = true;
btnPause.addEventListener(MouseEvent.CLICK, pois);
function pois(event:MouseEvent):void{
stage.frameRate = 0;
bg.visible = true;
bg2.visible = false;
gril.visible = false;
linya.visible = false;
btnPause.visible = false;
pauseWin.visible = true;
qnaWin.visible = false;
corekWin.visible = false;
maliWin.visible = false;
scorer.visible = false;
timer.visible = false;
forward.visible = false;
gameOverWin.visible = false;
}
pauseWin.btnResume.addEventListener(MouseEvent.CLICK, gorau);
function gorau(event:MouseEvent):void{
bg.visible = true;
bg2.visible = false;
gril.visible = true;
linya.visible = true;
btnPause.visible = true;
pauseWin.visible = false;
qnaWin.visible = false;
corekWin.visible = false;
maliWin.visible = false;
scorer.visible = false;
timer.visible = false;
forward.visible = true;
gameOverWin.visible = false;
}
pauseWin.btnQtm.addEventListener(MouseEvent.CLICK, kweet);
function kweet(event:MouseEvent):void{
gotoAndStop(1, "Scene 1");
}
/*var objectoriginalX:Number;
var objectoriginalY:Number;*/
**corekWin.btnGo.addEventListener(MouseEvent.CLICK, gorabelx);**//this is in the line 160, the main problem
function gorabelx(event:MouseEvent):void{
bg2.visible = true;
bg.visible = false;
//mcbackground.room.pinto(scaleY =-1);
}
//timer.timee.text=fl_SecondsToCountDown.toString();
fl_CountDownTimerInstance.start();
fl_CountDownTimerInstance.addEventListener(TimerEvent.TIMER, foo);
function foo(event:TimerEvent):void
{
fl_SecondsToCountDown--;
timer.timee.text=fl_SecondsToCountDown.toString();
trace(fl_SecondsToCountDown + " seconds");
if(fl_SecondsToCountDown == 0){
gameOverWin.visible = true;
}
}
gameOverWin.btnTry.addEventListener(MouseEvent.CLICK, tryk);
function tryk(event:MouseEvent):void{
bg.visible = true;
bg2.visible = false;
gril.visible = true;
linya.visible = true;
btnPause.visible = true;
pauseWin.visible = false;
qnaWin.visible = false;
corekWin.visible = false;
maliWin.visible = false;
scorer.visible = false;
timer.visible = false;
forward.visible = true;
gameOverWin.visible = false;
}
糟糕!我的代码太长了。我多次检查我的代码,没有任何错误,我也调试它,这种错误仍然出现。我已经声明了corekWin(movieclip),但是corekWin里面的btnGo(另一个能够点击的动画片段)并不需要声明它,对吧?因为corekWin已经声明了。
我试图解决这个错误,不幸的是,它失败了。我仔细检查了一下。您认为这段代码的问题是什么?
答案 0 :(得分:1)
关于这一行:
var corekWin:MovieClip = new MovieClip;
您刚刚创建了一个新的空白(空)MovieClip对象,其引用名称为corekWin
,因为您从未做过corekWin.addChild(btnGo);
,但您无法说出来;
corekWin.btnGo.addEventListener(MouseEvent.CLICK, gorabelx);
失败,因为corekWin
为空new Movieclip
,它不包含任何btnGo
个对象。
可能的解决方案:
如果corekWin
是图书馆(ctrl + L)中的MovieClip,那么您应该给它一个链接名称(右舔并转到属性并提供链接名称,例如将其命名为mc_corekWin
)。
现在,在您的代码中,您可以实例化现有的MovieClip,而不是创建一个新的空的...:
var corekWin : mc_corekWin = new mc_corekWin();
在调整任何视觉方面之前,请先通过stage.addChild(corekWin);
将其添加到舞台上,然后您可以执行corekWin.visible
或corekWin.alpha
,依此类推。
修改:
如果您的MC已经放置在舞台上(在运行时),那么您不需要创建new Movieclip
(甚至是new mc_corekWin
)变量。只需通过您提供的实例名称引用MC。
要撤消链接,只需返回图书馆中的MC属性,然后取消勾选“导出for Actionscript”框。
要添加实例名称,请单击MC(在舞台上单击它,而不是库)并打开属性选项卡(ctrl + F3)然后会看到一个准备好你喜欢名字的部分。您键入的名称(并按Enter键更新)将在代码中使用。
基本上,如果MC xyz
已经在舞台上,您不需要var xyz:MovieClip = new MovieClip;
(这将覆盖舞台上的MC)以通过代码控制它,只需给它一个实例名称,然后使用该名称在代码中引用MC。
可能您不需要gril
和linya
等变量为new MovieClip
。尝试取消注释(使用//
)并查看它们现在是否“不可见”。