A Flash Developer Resource Site

Results 1 to 6 of 6

Thread: weird #1009 error

  1. #1
    Junior Member
    Join Date
    Mar 2011
    Posts
    12

    weird #1009 error

    I'm having problems working out a bug in my shooting code for the hero ship in a new game I am developing.

    the code is pretty straight forward nothing fancy. Just press space and send the bullet movie clip across the screen.

    I am getting intermittent #1009 errors when adding the child to the stage.
    Code:
    if(Key.isDown(Keyboard.SPACE) && shootLimiter > 8)
    {
    				trace('51');
    				shootLimiter = 0;
    				trace('53');
    				var bullet:MovieClip = new HeroAmmo1();
    				trace('55');
    				stage.addChild(bullet);
    				trace('57');
    				bullet.scaleX = .25;
    				trace('59');
    				bullet.scaleY = .25;
    				trace('61');
    				bullet.x = this.x + 38;
    				trace('63');
    				bullet.y = this.y + 7;
    				trace('65');
    				Game.heroBullets.push(bullet);
    				trace('67');	
    }
    i put the traces in on every other line to pin point where the problem is coming from.
    the #1009 error shows up the in output dialog like this...

    Code:
    51
    53
    55
    TypeError: Error #1009: Cannot access a property or method of a null object reference.
    	at HeroShip/moveShip()
    51
    53
    55
    57
    59
    61
    63
    65
    67
    51
    53
    55
    TypeError: Error #1009: Cannot access a property or method of a null object reference.
    	at HeroShip/moveShip()
    51
    53
    55
    57
    you will see that the type error shows up after line 55, which is the stage.addChild(bullet) line.

    Can you think of any reason this would be happening. You can also see that it does not happen all the time. there are times when the lines run straight through from 51 to 67 just as the should.

    Any help would be really appreciated.

    Thanks,
    C

  2. #2
    When you know are. Son of Bryce's Avatar
    Join Date
    Aug 2002
    Location
    Los Angeles
    Posts
    839
    This error is from something that either doesn't exist or you don't have a reference too, check this out.

    You can check to see if the bullet exists in the trace. If it exists, it will display the class name in the trace.
    PHP Code:
    trace('55' bullet); 
    I'm not sure why you're calling "stage.addChild()", but that may be a problem as well. Just try addChild(), unless you have a specific reason to call the stage. Also, I believe you can't call "stage" unless the class making the call has been added to the stage already.

    It's weird that it doesn't happen every time, but trying these things may narrow down what the problem may be.

  3. #3
    Junior Member
    Join Date
    Mar 2011
    Posts
    12
    thanks for the link ..
    I tried your trace and basically came up with the same thing.

    Code:
    53[object HeroAmmo1]
    TypeError: Error #1009: Cannot access a property or method of a null object reference.
    	at HeroShip/moveShip()
    53[object HeroAmmo1]
    55[object HeroAmmo1]
    57[object HeroAmmo1]
    59[object HeroAmmo1]
    61[object HeroAmmo1]
    63[object HeroAmmo1]
    65[object HeroAmmo1]
    53[object HeroAmmo1]
    TypeError: Error #1009: Cannot access a property or method of a null object reference.
    	at HeroShip/moveShip()
    53[object HeroAmmo1]
    55[object HeroAmmo1]
    57[object HeroAmmo1]
    59[object HeroAmmo1]
    61[object HeroAmmo1]
    63[object HeroAmmo1]
    65[object HeroAmmo1]
    53[object HeroAmmo1]
    TypeError: Error #1009: Cannot access a property or method of a null object reference.
    	at HeroShip/moveShip()
    in reference to the stage.addChild(bullet)

    that's how I add all my movie clips to the stage. I tried using just addChild(bullet) and the bullet doesn't show up on the stage.

    I am using a Key press class that mimics as2 calls to make it easier for me. This key press class initializes with this call:

    Code:
    Key.initialize(stage);
    -- see attachment if interested.

    it seems like the game is actually working though which boggles my mind. All the points and hits and explosions work just fine .. but the output window throws that 1009 error.

    C
    Attached Files Attached Files

  4. #4
    When you know are. Son of Bryce's Avatar
    Join Date
    Aug 2002
    Location
    Los Angeles
    Posts
    839
    Under the "Publish Settings" for your FLA, there's an option for "Permit debugging". Select that, it'll give you an actual line number for the error you're seeing. I'm thinking it's something that's not even related to the bit of code you're posting.

  5. #5
    Junior Member
    Join Date
    Mar 2011
    Posts
    12
    ok .. so i did the debugging and it get this error
    Code:
    TypeError: Error #1009: Cannot access a property or method of a null object reference.
    	at HeroShip/moveShip()[C:\Users\Chris\Documents\My Dropbox\flash play\stp\HeroShip.as:54]
    here is the code
    Code:
    			if(Key.isDown(Keyboard.SPACE) && shootLimiter > 8)
    			{
    				shootLimiter = 0;
    				var bullet:MovieClip = new HeroAmmo1();
    				//trace('53' + bullet); 
    				stage.addChild(bullet);
    				//trace('55' + bullet);
    				bullet.scaleX = .25;
    				//trace('57' + bullet);
    				bullet.scaleY = .25;
    				//trace('59' + bullet);
    				bullet.x = this.x + 55 ;
    				//trace('61' + bullet);
    				bullet.y = this.y + 9;
    				//trace('63' + bullet);
    				Game.heroBullets.push(bullet);
    				//trace('65' + bullet);
    			}
    line 54 is the addChild and you can see the bullet is cast just above it.
    Is it possible that the code is running to fast?

  6. #6
    Senior Member tonypa's Avatar
    Join Date
    Jul 2001
    Location
    Estonia
    Posts
    8,227
    Maybe the stage is not available, try adding bullets to container movie clip. Or check for stage != null before using addChild.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center