“TypeError: Error #1010: A term is undefined and h

2019-09-07 07:46发布

问题:

I'm creating an Android game using Adobe Animate CC for our thesis, and every time I test my work, at first, it works fine, but when I go to the main game, there's an error appears:

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]

And this is my code (including commented code):

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;
}

Oops! My code is too long. I checked my code in many times and nothing is wrong, I also debug it and this kind of error still appears. I already declare the corekWin (the movieclip) but the btnGo (the another movieclip which enables to click) inside of corekWin doesn't need to declare it, right? Because the corekWin is already declared.

I'm trying to fix that error, and unfortunately, it fails. I have double-checked it. What do you think is the problem with this code?

回答1:

regarding this line :

var corekWin:MovieClip = new MovieClip;

You just created a new blank (empty) MovieClip object with reference name corekWin, since you never did a corekWin.addChild(btnGo); you cannot say ;

corekWin.btnGo.addEventListener(MouseEvent.CLICK, gorabelx);

It fails because corekWin is an empty new Movieclip, it does not contain any btnGo object.

possible solution :

If corekWin is a MovieClip in your Library (ctrl+L), then you should give it a linkage name (right-lick and go to Properties and give a linkage name, for example call it mc_corekWin).

Now in your code you can instantiate that existing MovieClip instead of creating a new empty one... :

var corekWin : mc_corekWin = new mc_corekWin();

Before adjusting any visual aspects, add it to the stage via stage.addChild(corekWin); then later you can do corekWin.visible or corekWin.alpha and so on.

Edit :

If your MC is already placed on the stage (at runtime) then you don't need to create a new Movieclip(or even a new mc_corekWin) variable. Simply reference the MC by the instance name you gave it.

  • To undo the linkage just go back to the MC's properties in Library and un-tick that "Export for Actionscript" box.

  • To add an instance name, click on the MC (click it on stage, not Library) and open Properties tab (ctrl+F3) and you'll see a section ready for your preferred name. The name you type (and press Enter to update) will be used in code.

Basically if an MC xyz is already on stage you don't need var xyz:MovieClip = new MovieClip; (this will override the on-stage MC) to control it by code, just give it an instance name and then use the name to reference the MC in code.

Likely you don't need vars like gril and linya etc to be new MovieClip. Try un-commenting them (using //) and see if they now become "not visible".