TypeError: Error #1009 - I know how to fix it. But I don't know whats going on!
I have a project that I’m working on that includes working in different scenes and frames. It’s a book project with lots of pages (frames) and chapters (scenes) so I have can’t avoid working in a single frame (like a game). I get a runtime error (TypeError: Error #1009: Cannot access a property or method of a null object reference.) when accessing an object inside of a movieclip. However, I have identified the problem and know how to fix it. But when I fix it the functionality goes away. Here’s how it happens:
- On frame #1 of Scene 2 I click on a button to go to a frame #2.
- On frame #2 is the offending code:
stage.addEventListener(MouseEvent.MOUSE_UP, moveChapters);
//********************Navigation Bar code ********************//
function moveChapters(event:MouseEvent):void
{
if(event.target == bottomNav.Chapter_1)
{
trace("Chapter #1 is working!");
}
}
- FYI, this code is part of a navigation bar the will take the user to different chapters. It is visible on stage. I haven't fully built it yet. For example, "if( event.target == bottomNav.Chapter_1)" will take the user to chapter 1, "bottomNav.Chapter_2," will take the user to chapter 2, so on and so forth. "bottomNav" is a movieclip and "Chapter_1" is a button inside it.
- When I go back to frame #1 of Scene 2 and then click on “Home” button to go back to the main page (Frame #1 of Scene #2) I get the Error #1009.
- When I comment out the “if(event.target == bottomNav.Chapter_1)” I don’t get the error but know I don’t have any functionality.
Is there a better way to do this?
