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

I don't understand why I am getting an error 1009

New Here ,
Jul 31, 2014 Jul 31, 2014

this is the code :

  function checkShoot():void

  {

  if (player.isShooting == true)

  {

   var bullet:Bullet = new Bullet(player.x,player.y,player.playerDir);

  stage.addChild(bullet);

  trace(player.playerDir);

  player.isShooting = false;

  }

  }

  function frameHandler(e:Event):void

  {

  if (platform.hitTestPoint(bullet.x + 31,bullet.y,true))    //it says the error is coming from here

  {

  trace("HIT PLATFORM:" + counter);

  counter++;

  }

I don't understand why this error is occurring. Please help me.

TOPICS
ActionScript
166
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 Expert ,
Jul 31, 2014 Jul 31, 2014

bullet is local to checkShoot.  ie, it doesn't exist in frameHandler so that if statement will trigger a 1009 error

you can remedy that error by 'typing' bullet outside checkShoot, but they may cause other problems because you'll be using one reference (bullet) to identify more than one object (assuming you call checkShoot more than once).

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
New Here ,
Aug 01, 2014 Aug 01, 2014

Thanks I fixed it. I am adding the bullets to and array and hit testing the bullets in the array

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 Expert ,
Aug 01, 2014 Aug 01, 2014
LATEST

you're welcome.

don't forget to loop through your array from end to start (not start to end) if you're removing array elements that are off-stage and no longer need to occupy memory.

p.s. please mark helpful/correct responses.

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