我正在使用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(影片剪辑)但是corekWin内部的btnGo(另一个允许点击的影片剪辑)不需要声明它,对吧?因为corekWin已经被声明了
我试图修复这个错误,不幸的是,它失败了。我已经仔细检查过了。你认为这段代码有什么问题?
关于这一行:
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。
要撤销链接只需回到Library中的MC属性并取消勾选"Export for Actionscript"框。
要添加实例名称,单击MC(在舞台上单击它,而不是库)并打开Properties选项卡(ctrl+F3),您将看到为您首选的名称准备的部分。您输入的名称(按Enter键更新)将在代码中使用。
基本上,如果一个MC xyz
已经在舞台上,你不需要var xyz:MovieClip = new MovieClip;
(这会覆盖舞台上的MC)来通过代码控制它,只需要给它一个实例名,然后使用该名称在代码中引用MC。
可能你不需要像gril
和linya
这样的变量为new MovieClip
。尝试取消注释(使用//
),看看它们现在是否变得"不可见"。