PDA

View Full Version : Cannot access a property or method of a null object reference



mrbelv
December 9th, 2008, 06:37 PM
This seems like it should be simple.

I've inherited a Flash file from a designer that I have to now make dynamic. I'm trying to keep as much of the original straucture as possible - meaning - that there's a lot of timeline stuff going on in here.

I have a main movie clip called "contentMC". Inside this clip, the designer has three navigation tabs. When you click one, they have a "gotoAndStop" action to take you to the appropriate frame label. Each one of the tabs is a button.

On the main timeline, I have the following code:



contentMC.tab1.addEventListener(MouseEvent.MOUSE_U P, firstTab);

function firstTab(e:MouseEvent):void {
contentMC.gotoAndStop("firstTabContent");
}


I get the following error:

TypeError: Error #1009: Cannot access a property or method of a null object reference.
at TVLI_12_fla::MainTimeline/firstTab()

And yes, "tab1" is a button, but why this would make any difference whatsoever is beyond me. This is about as basic as it gets. I don't get the error if I don't try and do the "gotoAndStop" action.

Any help with this would be greatly appreciated.

creatify
December 9th, 2008, 06:58 PM
did you trace(contentMC.tab1) before the addEventListener - making sure it's on a frame beneath the code? Is this a compile-time error or run-time?

Krilnon
December 9th, 2008, 07:11 PM
It has to be a runtime error… and it's happening inside of firstTab so it's probably contentMC that's null. However, there's not really enough code to tell what's going on, since I created a replica of what we know of the situation and I don't get a similar error, so I'm guessing that some relevant code has been left out, or something.

mrbelv
December 10th, 2008, 09:55 AM
No code whatsoever has been left out. "contentMC" and all the tabs trace out. I guess this is just another example of how much better AS3 is than AS2. Now I get to spend a whole day trying to debug an error messaage that tells me absolutely nothing. Thanks Adobe!