Skip to main content
Participant
March 28, 2012
Answered

Cannot access a property or method of a null object reference.

  • March 28, 2012
  • 2 replies
  • 1373 views

Hi there everyone, I've been working on a multimedia project for I.T course.

I have no experience in actionscript 3 whatsoever.


I keep getting this message in flash cs4 when I try to actions to the my menu buttons



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

at Enigma_fla::MainTimeline/frame1()"

stop();

enter_btn.addEventListener(MouseEvent.CLICK,enter_btnClick);

home_btn.addEventListener(MouseEvent.CLICK,home_btnClick);

gallery_btn.addEventListener(MouseEvent.CLICK,gallery_btnClick);

depart_btn.addEventListener(MouseEvent.CLICK,depart_btnClick);

courses_btn.addEventListener(MouseEvent.CLICK,courses_btnClick);

interact_btn.addEventListener(MouseEvent.CLICK,interact_btnClick);

function enter_btnClick(ev:MouseEvent):void

{

          gotoAndPlay("enigmastart");

}

function home_btnClick(ev:MouseEvent):void

{

          gotoAndPlay("enigmastart");

}

function gallery_btnClick(ev:MouseEvent):void

{

          gotoAndPlay("galleria");

}

function depart_btnClick(ev:MouseEvent):void

{

          gotoAndPlay("department");

}

function courses_btnClick(ev:MouseEvent):void

{

          gotoAndPlay("courses");

}

function interact_btnClick(ev:MouseEvent):void

{

          gotoAndPlay("interact");

}

 

stop();


This topic has been closed for replies.
Correct answer sinious

You don't need 2 stop();s on the same frame but that's another thing.

What it typically means is one of those buttons does not exist where you're trying to assign the function to. Try a debug instead of test movie and usually it will show you what line is failing (CTRL+SHIFT+ENTER instead of just CTRL+ENTER, or menu item Debug->Debug Movie->In Flash Professional).

You can't "predefine" those assignments before the clips they're being assigned to actually exist. So make sure on that frame where that code is all of those buttons both exist and are named exactly like they are above. Sometimes someone accidently duplicates an existing button and forgets to change the instance name.

2 replies

TheOnionAuthor
Participant
March 28, 2012

Thank you guys I got it fixed The problem was as Sinious said, I didnt have the buttons in the keyframe where the actionscript was.

sinious
Legend
March 28, 2012

Glad you got it fixed. Good luck!

sinious
siniousCorrect answer
Legend
March 28, 2012

You don't need 2 stop();s on the same frame but that's another thing.

What it typically means is one of those buttons does not exist where you're trying to assign the function to. Try a debug instead of test movie and usually it will show you what line is failing (CTRL+SHIFT+ENTER instead of just CTRL+ENTER, or menu item Debug->Debug Movie->In Flash Professional).

You can't "predefine" those assignments before the clips they're being assigned to actually exist. So make sure on that frame where that code is all of those buttons both exist and are named exactly like they are above. Sometimes someone accidently duplicates an existing button and forgets to change the instance name.

TheOnionAuthor
Participant
March 28, 2012

Alright I'll get right on that, thank you very much.

sinious
Legend
March 28, 2012

Just click on each button and look in the properties. The instance name text input should say the names that are listed there such as enter_btn, home_btn, etc. The name of the clip in the library is irrelevant, it's the instance name you care about which is in the properties panel when you have the clip selected on screen. If that solves it please mark this post answered. Good luck!