Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Error #1009

Community Beginner ,
Dec 15, 2014 Dec 15, 2014

Hello guys, i'm needing help (again) with a error, his name is Error #1009

TypeError: Error #1009: Não é possível acessar uma propriedade ou um método de uma referência de objeto nula.

  at TheAdventureofaTopHat_Scene1_fla::MainTimeline/loop()[TheAdventureofaTopHat_Scene1_fla.MainTimeline::frame1:101]

var maxHP:int = 100;

var currentHP:int = maxHP;

var percentHP:Number = currentHP / maxHP;

function updateHealthBar():void

{

  percentHP = currentHP / maxHP;

  healthBar.barColor.scaleX = percentHP;

}

function restartGame():void{

currentHP = maxHP;

updateHealthBar();

}

var leftPressed:Boolean = false;

var rightPressed:Boolean = false;

var upPressed:Boolean = false;

var downPressed:Boolean = false;

var leftBumping:Boolean = false;

var rightBumping:Boolean = false;

var upBumping:Boolean = false;

var downBumping:Boolean = false;

var leftBumpPoint:Point = new Point(-30, -55);

var rightBumpPoint:Point = new Point(30, -55);

var upBumpPoint:Point = new Point(0, -120);

var downBumpPoint:Point = new Point(0, 0);

var scrollX:Number = 0;

var scrollY:Number = 500;

var xSpeed:Number = 0;

var ySpeed:Number = 0;

var speedConstant:Number = 4;

var frictionConstant:Number = 0.9;

var gravityConstant:Number = 1.8;

var jumpConstant:Number = -35;

var maxSpeedConstant:Number = 18;

var doubleJumpReady:Boolean = false;

var upReleasedInAir:Boolean = false;

var keyCollected:Boolean = false;

var doorOpen:Boolean = false;

var currentLevel:int = 1;

var animationState:String = "idle";

var bulletList:Array = new Array();

var enemyList:Array = new Array();

var bumperList:Array = new Array();

stage.addEventListener(KeyboardEvent.KEY_DOWN, keyDownHandler);

stage.addEventListener(KeyboardEvent.KEY_UP, keyUpHandler);

stage.addEventListener(Event.ENTER_FRAME, loop);

addEnemiesToLevel1();

addBumpersToLevel1();

function addEnemiesToLevel1():void

{

  addEnemy(620, -115);

  addEnemy(900, -490);

  addEnemy(2005, -115);

  addEnemy(1225, -875);

}

function addBumpersToLevel1():void

{

    addBumper(500, -115);

    addBumper(740, -115);

}

function loop(event:Event):void{

  if(back.hitTestPoint(player.x + leftBumpPoint.x, player.y + leftBumpPoint.y, true)){  // HERE IS THE ERROR

  trace("leftBumping");

  leftBumping = true;

  } else {

  leftBumping = false;

  }

}

  if(back.hitTestPoint(player.x + rightBumpPoint.x, player.y + rightBumpPoint.y, true)){

  trace("rightBumping");

  rightBumping = true;

  } else {

  rightBumping = false;

}

  if(back.hitTestPoint(player.x + upBumpPoint.x, player.y + upBumpPoint.y, true)){

  trace("upBumping");

  upBumping = true;

  } else {

  upBumping = false;

}

  if(back.hitTestPoint(player.x + downBumpPoint.x, player.y + downBumpPoint.y, true)){

  trace("downBumping");

  downBumping = true;

  } else {

  downBumping = false;

    }

  if(leftPressed){

  xSpeed -= speedConstant;

  player.scaleX = -1;

  } else if(rightPressed){

  xSpeed += speedConstant;

  player.scaleX = 1;

  }

/*if(upPressed){

  ySpeed -= speedConstant;

} else if(downPressed){

  ySpeed += speedConstant;

}*/

  if(leftBumping){

  if(xSpeed < 0){

  xSpeed *= -0.5;

  }

  }

  if(rightBumping){

  if(xSpeed > 0){

  xSpeed *= -0.5;

  }

  }

  if(upBumping){

  if(ySpeed < 0){

  ySpeed *= -0.5;

  }

  }

  if(downBumping){ //if we are touching the floor

  if(ySpeed > 0){

  ySpeed = 0; //set the y speed to zero

  }

  if(upPressed){ //and if the up arrow is pressed

  ySpeed = jumpConstant; //set the y speed to the jump constant

  }

  //DOUBLE JUMP

  if(upReleasedInAir == true){

  upReleasedInAir = false;

  }

  if(doubleJumpReady == false){

  doubleJumpReady = true;

  }

  } else { //if we are not touching the floor

  ySpeed += gravityConstant; //accelerate downwards

  //DOUBLE JUMP

  if(upPressed == false && upReleasedInAir == false){

  upReleasedInAir = true;

  //trace("upReleasedInAir");

  }

  if(doubleJumpReady && upReleasedInAir){

  if(upPressed){ //and if the up arrow is pressed

  //trace("doubleJump!");

  doubleJumpReady = false;

  ySpeed = jumpConstant; //set the y speed to the jump constant

  }

  }

  }

  if(keyCollected == false){

         if(player.hitTestObject(back.other.doorKey)){

            back.other.doorKey.visible = false;

            keyCollected = true;

  trace("key collected");

  }

  }

  if(doorOpen == false){

  if(keyCollected == true){

  if(player.hitTestObject(back.other.lockedDoor)){

  back.other.lockedDoor.gotoAndStop(2);

  doorOpen = true;

  trace("door open");

  }

  }

  }

 

  if(xSpeed > maxSpeedConstant){ //moving right

  xSpeed = maxSpeedConstant;

  } else if(xSpeed < (maxSpeedConstant * -1)){ //moving left

  xSpeed = (maxSpeedConstant * -1);

  }

  xSpeed *= frictionConstant;

  ySpeed *= frictionConstant;

  if(Math.abs(xSpeed) < 0.5){

  xSpeed = 0;

  }

  scrollX -= xSpeed;

  scrollY -= ySpeed;

  back.x = scrollX;

  back.y = scrollY;

  sky.x = scrollX * 0.2;

  sky.y = scrollY * 0.2;

  if( ( leftPressed || rightPressed || xSpeed > speedConstant || xSpeed < speedConstant *-1 ) && downBumping){

  animationState = "running";

  } else if(downBumping){

  animationState = "idle";

  } else {

  animationState = "jumping";

  }

  if(player.currentLabel != animationState){

  player.gotoAndStop(animationState);

  }

  if (enemyList.length > 0) // if there are any enemies left in the enemyList

  {

  for (var i:int = 0; i < enemyList.length; i++) // for each enemy in the enemyList

  {

  if (bulletList.length > 0) // if there are any bullets alive

  {

  for (var j:int = 0; j < bulletList.length; j++) // for each bullet in the bulletList

  {

  if ( enemyList.hitTestObject(bulletList) )

  {

  trace("Bullet and Enemy are colliding");

  enemyList.removeSelf();

  bulletList.removeSelf();

  }

  // enemyList will give you the current enemy

  // bulletList will give you the current bullet

  // this will check all combinations of bullets and enemies

  // and see if any are colliding

  }

  }

  }

  }

//corralling the bad guys with bumpers

  if (enemyList.length > 0){ //enemies left in the enemyList?

    for (var k:int = 0; k < enemyList.length; k++){ // for each enemy in the enemyList

        if (bumperList.length > 0){

            for (var h:int = 0; h < bumperList.length; h++){ // for each bumper in the List

                if ( enemyList.hitTestObject(bumperList) ){

                    enemyList.changeDirection();

                        }

                    }

                }

            }

        }

//player and enemy collisions

  if (enemyList.length > 0){ //enemies left?

    for (var m:int = 0; m < enemyList.length; m++){ // for each enemy in the enemyList

        if ( enemyList.hitTestObject(player) ){

  trace("player collided with enemy");

  //code to damage player goes here, maybe integrate with a health bar?

  enemyList.removeSelf();

  }

  }

  }

function nextLevel():void{

  currentLevel++;

  trace("Next Level: " + currentLevel);

  if(currentLevel == 2){

    gotoLevel2();

  }

  // can be extended...

  // else if(currentLevel == 3) { gotoLevel3(); } // etc, etc.

}

function gotoLevel2():void{

  back.other.gotoAndStop(2);

  back.visuals.gotoAndStop(2);

  back.collisions.gotoAndStop(2);

  scrollX = 0;

  scrollY = 500;

  keyCollected = false;

  back.other.doorKey.visible = true;

  doorOpen = false;

  back.other.lockedDoor.gotoAndStop(1);

}

function keyDownHandler(e:KeyboardEvent):void{

  if(e.keyCode == Keyboard.A){

  leftPressed = true;

  } else if(e.keyCode == Keyboard.D){

  rightPressed = true;

  } else if(e.keyCode == Keyboard.W){

  upPressed = true;

  } else if(e.keyCode == Keyboard.S){

  downPressed = true;

  if(doorOpen && player.hitTestObject(back.other.lockedDoor)){

  //proceed to the next level if the player is touching an open door

  nextLevel();

  }

  }

}

function keyUpHandler(e:KeyboardEvent):void{

  if(e.keyCode == Keyboard.A){

  leftPressed = false;

  } else if(e.keyCode == Keyboard.D){

  rightPressed = false;

  } else if(e.keyCode == Keyboard.W){

  upPressed = false;

  } else if(e.keyCode == Keyboard.S){

  downPressed = false;

  }

  if(e.keyCode == Keyboard.SPACE){

  fireBullet();

  }

}

function fireBullet():void

{

  var playerDirection:String;

  if(player.scaleX < 1){

  playerDirection = "left";

  } else if(player.scaleX > -1){

  playerDirection = "right";

  }

  var bullet:Bullet = new Bullet(player.x - scrollX, player.y - scrollY, playerDirection, xSpeed);

  back.addChild(bullet);

  bullet.addEventListener(Event.REMOVED, bulletRemoved);

  bulletList.push(bullet);

}

function bulletRemoved(e:Event):void

{

  e.currentTarget.removeEventListener(Event.REMOVED, bulletRemoved); //this just removes the eventListener so we don't get an error

  bulletList.splice(bulletList.indexOf(e.currentTarget), 1); //this removes 1 object from the bulletList, at the index of whatever object caused this function to activate

}

function addEnemy(xLocation:int, yLocation:int):void

{

  var enemy:Enemy = new Enemy(xLocation, yLocation);

  back.addChild(enemy);

  enemy.addEventListener(Event.REMOVED, enemyRemoved);

  enemyList.push(enemy);

}

function addBumper(xLocation:int, yLocation:int):void

{

  var bumper:Bumper = new Bumper(xLocation, yLocation);

  back.addChild(bumper);

  bumper.visible = false;

  bumperList.push(bumper);

}

function enemyRemoved(e:Event):void

{

   e.currentTarget.removeEventListener(Event.REMOVED, enemyRemoved); //this just removes the eventListener so we don't get an error

   enemyList.splice(enemyList.indexOf(e.currentTarget), 1); //this removes 1 object from the enemyList, at the index of whatever object caused this function to activate

}

if some one can help me, thanks!

TOPICS
ActionScript
1.6K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

LEGEND , Dec 15, 2014 Dec 15, 2014

There are a few things in that line that it could be since there are a few things being targeted.

back

back.collisions

player

leftBumpPoint

So what you can do is place some traces just before that line to see if you can narrow down which is failing to be targeted...

trace("back ", back);

trace("back.collisions ", back.collisions);

trace("player ", player);

trace("leftBumpPoint ", leftBumpPoint);

if(back.collisions.hitTestPoint(player.x + leftBumpPoint.x, player.y + leftBumpPoint.y, true)){

Whichever one c

...
Translate
LEGEND ,
Dec 15, 2014 Dec 15, 2014

The 1009 error indicates that one of the objects being targeted by your code is out of scope.  This could mean that the object....

 

- is declared but not instantiated

- doesn't have an instance name (or the instance name is mispelled)

- does not exist in the frame where that code is trying to talk to it

- is animated into place but is not assigned instance names in every keyframe for it

- is one of two or more consecutive keyframes of the same objects with no name assigned in the preceding frame(s).

In your case the error is pointing at line 101 of frame 1.  Whatever object is being targeted in that line does not exist as far as the compiler sees it.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Dec 15, 2014 Dec 15, 2014

if(back.collisions.hitTestPoint(player.x + leftBumpPoint.x, player.y + leftBumpPoint.y, true)){


maybe the hittestpoint?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Dec 15, 2014 Dec 15, 2014

i dont know soo good flash i'm a newbie

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Dec 15, 2014 Dec 15, 2014

There are a few things in that line that it could be since there are a few things being targeted.

back

back.collisions

player

leftBumpPoint

So what you can do is place some traces just before that line to see if you can narrow down which is failing to be targeted...

trace("back ", back);

trace("back.collisions ", back.collisions);

trace("player ", player);

trace("leftBumpPoint ", leftBumpPoint);

if(back.collisions.hitTestPoint(player.x + leftBumpPoint.x, player.y + leftBumpPoint.y, true)){

Whichever one comes up null (or never comes up) is the one that is causing the error.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Dec 15, 2014 Dec 15, 2014

back  [object MovieClip]

back.collisions  [object BackgroundCollisionsContainer_3]

player  [object MovieClip]

leftBumpPoint  (x=-30, y=-55)

downBumping

maybe downBumping?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Dec 15, 2014 Dec 15, 2014

Maybe   I don't know what you did and I don't see downBumping in the line of code you identified as line 101

If you try to trace the value of downBumping and it does not show, but the error occurs right after that trace output, then you can be pretty sure it is where the problem lies.  If so, check the list of reasons I provided to see if one of them applies.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Dec 16, 2014 Dec 16, 2014

when i put those traces, appear those things:

back  [object MovieClip]

back.collisions  [object BackgroundCollisionsContainer_3]

player  [object MovieClip]

leftBumpPoint  (x=-30, y=-55)

i think no one is null,

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Dec 16, 2014 Dec 16, 2014

What is line 101 of frame 1?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Dec 16, 2014 Dec 16, 2014

if(back.collisions.hitTestPoint(player.x + leftBumpPoint.x, player.y + leftBumpPoint.y, true)){

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Dec 16, 2014 Dec 16, 2014

What is the complete error message?  What precedes the error message in the output panel when you get the error message?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Dec 16, 2014 Dec 16, 2014

nothing, appear only this

TypeError: Error #1009: Não é possível acessar uma propriedade ou um método de uma referência de objeto nula.

  at TheAdventureofaTopHat_Scene1_fla::MainTimeline/loop()[TheAdventureofaTopHat_Scene1_fla.Ma inTimeline::frame1:101]

and appear,appear then when i close the swf, stop appearing the error, like when the swf is open, never stop appearing this error,when close the swf stop the error,

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Dec 16, 2014 Dec 16, 2014

what to do?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Dec 16, 2014 Dec 16, 2014

Show the code with the traces in it.  You should be getting the traces each time the error occurs if you placed it where I told you to put it.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Dec 17, 2014 Dec 17, 2014
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Dec 17, 2014 Dec 17, 2014

That is not what I asked you to show, but it does show that the trace code is probably not where I said to put it.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Dec 17, 2014 Dec 17, 2014

you mean where i put the trace on the 'action'? http://prntscr.com/5htdfo

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Dec 17, 2014 Dec 17, 2014

Yes.  You did not put the code where I said to.  Go back to my response and read where I said to put it.  The way you have it it will execute as soon as the file starts.  You want it to execute when that line of code (101) executes.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Dec 17, 2014 Dec 17, 2014

it say back is null *-*

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Dec 17, 2014 Dec 17, 2014

i have an instance named back, but how i put properties to it?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Dec 17, 2014 Dec 17, 2014

ok, i make some changes, and now i'm getting this error

back  [object MovieClip]

back.collisions  undefined

player  [object MovieClip]

leftBumpPoint  (x=-30, y=-55)

TypeError: Error #1010: Um termo é indefinido e não tem propriedades.

  at TheAdventureofaTopHat_Scene1_fla::MainTimeline/loop()[TheAdventureofaTopHat_Scene1_fla.MainTimeline::frame1:104]

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Dec 17, 2014 Dec 17, 2014

you know what to do?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Dec 17, 2014 Dec 17, 2014

A 1010 error is very similar to a 1009 error.  You should be able to see what you need to fix next since the trace indicates where the problem lies...

back.collisions  undefined

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Dec 17, 2014 Dec 17, 2014

omg, i changed a lot of instances, and i fix the back.collisions, and now is speaking again that back is null, WHATA shit!!!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Dec 17, 2014 Dec 17, 2014
LATEST

Hey Ned, are you here?, i have the instance name back, for the background, and this are my layers http://prntscr.com/5i6p1t,

i dont know why this bug is happening, the 'back' is in the layer background

OBS: is the error #1009 again

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines