Skip to main content
Participating Frequently
August 20, 2011
Question

null object reference

  • August 20, 2011
  • 3 replies
  • 1120 views

I'm creating a movie clip button and for the out state I have this:

web_btn.addEventListener(MouseEvent.MOUSE_OUT, at_out);

function at_out(event:MouseEvent):void {

web_btn.gotoAndPlay(30-(web_btn.currentFrame-11));

}

It gives me this error when I click the button:

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

at index_fla::web_mc_37/at_out()

What is it?

This topic has been closed for replies.

3 replies

Participating Frequently
August 20, 2011

Got it, when I used the code snippet I thought it was mouse roll out and I didn't even looked at the code!

So it's ROLL_OUT and not MOUSE_OUT

Ned Murphy
Legend
August 20, 2011

MOUSE_OUT is as legitimate as ROLL_OUT, so it's hard to see how that fixed anything, especially since it didn't involvre the line of code you said was causing the problem.  It could make a difference if you were using 'event.target' in your code though.

Participating Frequently
August 20, 2011

This is the code for the button:

web_btn.buttonMode = true;

web_btn.addEventListener(MouseEvent.ROLL_OVER, at_over);

web_btn.addEventListener(MouseEvent.ROLL_OUT, at_out);

web_btn.addEventListener(MouseEvent.CLICK, at_down);

function at_over(event:MouseEvent):void {

web_btn.gotoAndPlay("over");

}

function at_out(event:MouseEvent):void {

web_btn.gotoAndPlay(15-(web_btn.currentFrame-6));

}

function at_down(event:MouseEvent):void {

web_btn.gotoAndPlay("down");

}

The function "at_out" reverses the roll_over effect!

Now it's all working, but the only issue is the filesize, and I'm trying to make some functions global for other buttons that by the way have diferent sizes.

I'm gonna try classes!

Participating Frequently
August 20, 2011

The error is in this statement:

web_btn.gotoAndPlay(30-(web_btn.currentFrame-11));

The whole thing works fine, all the effects are correct, the only error is that gives me that error!

Ned Murphy
Legend
August 20, 2011

Try tracing the web_btn inside that function to see if it does not exist when that code executes

StoneChameleon
Inspiring
August 20, 2011

You seem to be missing a reference for or in your web_btn