dcsimg
A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: #1009: Cannot access a property or method of a null object reference.

  1. #1
    FrazzledNewbie
    Join Date
    Mar 2007
    Location
    Los Angeles
    Posts
    23

    #1009: Cannot access a property or method of a null object reference.

    I've googled this error a ton but haven't found anything relevant yet. I'm in an AS 3.0 class (as in a room with people and a teacher and text books and lectures .. not a class file) and we're all getting the same errors.

    Basically we all have to create a file with 10 buttons. Each button needs to go to a new frame. On that frame we have a separate actionscript 3.0 code that does something (for this question, I do not think it matters... each script on each frame has to show off a different AS 3.0 code that proves we've learned something).

    So let's say we have 11 frames. Frame 1 has the navigation and the intro. Frames 2-11 each have a stop(); and a new code.

    So each frame has different content (except for the background and navigation buttons which are consistent on all frames).

    The problem is that on one frame we have an ENTER_FRAME on a movie clip that points to a specific function. On that particular frame it works fine but once you navigate to a new frame on the timeline - the function continues to run in the background and we get the "#1009: Cannot access a property or method of a null object reference" error. (I assume it's because on the new frame the content from the previous frame no longer exists. By content I mean the movie_clips/buttons/etc..)

    Once the functions start to run on top of each other in the background - the entire SWF just devolves and breaks down because it's trying to do too many things at once.

    removeListener seems like the obvious answer but on each new frame it generates an error because it can't see the content from the previous frame on which the Listener was added. Putting it on the navigation button codes doesn't seem to work either.

    Any theoretical suggestions?

  2. #2
    Total Universe Mod jAQUAN's Avatar
    Join Date
    Jul 2000
    Location
    Honolulu
    Posts
    2,429
    You'll have to paste the section of your code highlighting the problem.
    When you say on Frame 1 you have an Enter_Frame, does the listener object exist there and whos stage property did you attach the listener to?

    The Enter_Frame event is broadcast every single frame (even if you only have a 1 frame movie) according to the framerate. If you have something that needs to be updated every frame AND exists on every frame, listen for that sprites Enter_Frame event.

  3. #3
    Ө_ө sleepy mod
    Join Date
    Mar 2003
    Location
    Oregon, USA
    Posts
    2,441
    Quote Originally Posted by Ravie13
    I assume it's because on the new frame the content from the previous frame no longer exists. By content I mean the movie_clips/buttons/etc..
    That sounds like the problem right there...but without code I'm just guessing:

    You're putting the enter-frame event on something and then losing the scope so the listener breaks and you can't target it anymore to stop it. For starters, break out some traces to find out what's dissappearing (you should see some trace go from [object Movieclip] to undefined right before the apocalypse).

    Once you isolate the problem object(s), throw in some if...then code to compensate. if(your mc is not undefined){...}, that should kill off any errors youre getting. Thats still not a great solution though.

    Once you detect that things have gone toe-up, you need to kill that event listener off. Otherwise you're stacking enterFrames up forever and bogging down your machine. Here's a handy snippet that you can run inside an event listener that will kill it:

    PHP Code:
                    e.target.removeEventListener(e.typearguments.callee);
    //  where e is your incoming event object 

  4. #4
    Junior Member
    Join Date
    Dec 2008
    Posts
    13
    Hi there I also have a problem with this error #1009!

    When I use the debugger it says:
    "TypeError: Error #1009: Cannot access a property or method of a null object reference.
    at PlatformGame/checkCollisions()[D:\game\PlatformGame.as:2445]
    at PlatformGame/gameLoop()[D:\game\PlatformGame.as:951]".

    On line 2445 in the function checkCollisions() in my as3 file is the following code:

    Code:
       line 2445:                      if (hero.mc.hitTestObject(boss.mc))
       line 2446:
       .				{ 
       .					if (hero.hit && hero.direction == boss.direction)
       .					{
    					Score_Font_Enemy.Health_Bar.width -=2.5;
    						bossLives--;
    						BossDie();
    					}else if(hero.hitted){
    						
    						} else {
    						heroHitted();
    					}
    				}
    I can't figure it out. I know that "boss.mc" is null but don't know how to fix it. The mc on the stage has its reference name "boss". This error happens when I enter the frame with the boss.
    Thanks for the help

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