Welcome to WebmasterWorld Guest from 54.145.71.115

Forum Moderators: open

Message Too Old, No Replies

Actionscript 3.0 debuggin question.

Need help understanding an error message.

     
7:23 pm on Jun 22, 2007 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Dec 15, 2003
posts:2606
votes: 0


Hey all...

Flash newb here. I will really appreciate any help that can be given.

So I have four buttons that I created in flash. I used the primitive rectangle tool and created a rectangle. I converted it to a symbol of type button. I gave the button an instance name. I then create 3 more using the same procedure and gave them all unique instance names.

I want to add an event listener to the button. I followed the technique used in a tutorial and it works in the tutorial and not for me.

Here is a code snippet:
*****************

home_button.addEventListener(MouseEvent.MOUSE_OVER,runHomeButton);
gallery_button.addEventListener(MouseEvent.MOUSE_OVER,runGalleryButton);
press_button.addEventListener(MouseEvent.MOUSE_OVER,runPressButton);
contact_button.addEventListener(MouseEvent.MOUSE_OVER,runContactButton);

function runHomeButton(e:MouseEvent):void {
home_popup.visible = true;
home_popup.play();
}

function runGalleryButton(e:MouseEvent):void {
gallery_popup.visible = true;
gallery_popup.play();
}

function runPressButton(e:MouseEvent):void {
press_popup.visible = true;
press_popup.play();
}

function runContactButton(e:MouseEvent):void {
contact_popup.visible = true;
contact_popup.play();
}
*****************

Now when this runs I get the error of:
*****************
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at flash_skin_fla::MainTimeline/flash_skin_fla::frame1()
*****************

I know that it is the code that is trying to put the assign the event listener because when I remove that block then it works fine. When i add even one of the lines back in it errors again.

Anyone have any insight as to why? The code is identical to the example I followed.

7:59 pm on June 22, 2007 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Dec 15, 2003
posts:2606
votes: 0


Sorry if you read this already..... I found that the buttons I am referencing in frame 1 aren't actually brought to the stage until a frame later on...... this is why it was a null object..... I copied them over to the first frame and it is working now.