Skip to main content
Known Participant
March 7, 2013
Answered

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

Hello,

I have some issues in understanding y i get this error, here is my code for the menu btns of the site:

// handle events for menu btns

 

weDance_btn.addEventListener(MouseEvent.CLICK, clickWedance);

inFan_btn.addEventListener(MouseEvent.CLICK, clickInFan);

karnivale_btn.addEventListener(MouseEvent.CLICK, clickkarnivale);

outOfSpace_btn.addEventListener(MouseEvent.CLICK, clickoutOfSpace);

nightmare_btn.addEventListener(MouseEvent.CLICK, clickNightmare);

karnivale2_btn.addEventListener(MouseEvent.CLICK, clickKarnivale2);

bucharest_btn.addEventListener(MouseEvent.CLICK, clickBucharest);

function clickWedance(evtObj:MouseEvent) {

    //trace shows what's happening .. in the output window

    trace("The wedance btn was clicked!");

    gotoAndStop("weDance");

}

function clickInFan(evtObj:MouseEvent) {

    //trace shows what's happening .. in the output window

    trace("The clubspace btn was clicked!");

    gotoAndStop("inFan");

}

function clickkarnivale(evtObj:MouseEvent) {

    //trace shows what's happening .. in the output window

    trace("The kar btn was clicked!");

    gotoAndStop("karnivale");

}

function clickoutOfSpace(evtObj:MouseEvent) {

    //trace shows what's happening .. in the output window

    trace("The outofspace btn was clicked!");

    gotoAndStop("outOfSpace");

}

function clickNightmare(evtObj:MouseEvent) {

    //trace shows what's happening .. in the output window

    trace("The nightmare btn was clicked!");

    gotoAndStop("Nightmare");

}

function clickKarnivale2(evtObj:MouseEvent) {

    //trace shows what's happening .. in the output window

    trace("The carnivale2 btn was clicked!");

    gotoAndStop("karnivale2");

}

function clickBucharest(evtObj:MouseEvent) {

    //trace shows what's happening .. in the output window

    trace("The bucharest btn was clicked!");

    gotoAndStop("bucharest");

}

it works with no errors!

But now i need to add another btn on the OutofSpace page and this is it:

spacePic_btn.addEventListener(MouseEvent.CLICK, clickSpacePic);

function clickSpacePic(evtObj:MouseEvent) {

    //trace shows what's happening .. in the output window

    trace("The SpacePic btn was clicked!");

    gotoAndStop("SpacePics");

}

when i test movie in the output i get the error  and the btn doesnt work.!  Why?

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

    at WeDance_fla::MainTimeline/frame240()[WeDance_fla.MainTimeline::frame240:26]   <<<< >>>>   spacePic_btn.addEventListener(MouseEvent.CLICK, clickSpacePic); 

    at flash.display::MovieClip/gotoAndStop()

    at WeDance_fla::MainTimeline/clickoutOfSpace()[WeDance_fla.MainTimeline::frame2:61]     <<<<<>>>>>  //trace shows what's happening .. in the output window

Note: i put the code for the spacePic_btn  on the keyframe where outofspace page starts, it it counts

PLease help.

thank You!

This topic is closed to new replies. Start a new post to keep the conversation going.
Ned Murphy
Ned MurphyCorrect answer
Legend
March 7, 2013

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).

7 replies

Ned Murphy
Ned MurphyCorrect answer
Legend
March 7, 2013

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).

Translate
bogdano_Author
Known Participant
March 7, 2013

can you elaborate pls what  1st " - "  and 5th " - "  means ?

i checked it has corect instance name; the btn exist in the frame where the code is but doesnt exist in the frame where the code tells it to gotoAndStop;  also the keyframes labels are correct.

 

also y do you think it refers to this line too   ?

at WeDance_fla::MainTimeline/clickoutOfSpace()[WeDance_fla.MainTimeline: :frame2:61]  (on this line is this > //trace shows what's happening .. in the output window)

i dont know what to do

thnk you

Translate
Ned Murphy
Legend
March 7, 2013

The 1st one would only apply if you are dynamically creating the object...

var someObj:MovieClip;  // declared

var someObject:MovieClip = new MovieClip(); // declared and instantiated

The 5th one involves having the same object in two adjacent keyframes but the name is only assign in the second frame.  It will inherit the name (or lack of name) of the one in the frame before it.

Based on the error message, the problem is in line 26 of frame 2.  If that line is...

     spacePic_btn.addEventListener(MouseEvent.CLICK, clickSpacePic);

Then the problem is that as far as the code is concerned, spacePic_btn does not exist in that frame when the code executes.

If that is not line 26, then if you show line 26 that will be helpful.

Any line numbers after the first iun the error message are just part of the trail that leads to the error occuring

Translate