flash error 1009

here’s the error i get:

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

here’s my code:

import flash.display.MovieClip;
import flash.events.EventDispatcher;
servicesbtn.addEventListener(MouseEvent.MOUSE_OVER,services);
function services(MouseEvent):void {

gotoAndStop(2);

}
servicesmask.addEventListener(MouseEvent.MOUSE_OVER,servegone);
function servegone(MouseEvent):void {

gotoAndStop(1);

}

what’s the problem?

forgot to add, everything works until i add the second mouse event.

bump

is “servicesmask” a valid instance name on that frame?

Also, for events, when you are writing the function you need to give the parameter a name so you can reference it if need be:

Error #1009 is rather infamous in ActionScript 3.0 as it can be incredibly vague without pointing to the real problem. You say it doesn’t occur until you go to add the second event listener so that makes me think you don’t have the “servicesmask” instantiated. Maybe theres a typo where you set it up?

i fixed it by moving my second mouse event to the second frame instead of keeping it in my dedicated actions frame. any ideas why that worked?

what is the parameter used for? i am a complete as3 noob.

and thanks for the help. i was worried i wasn’t going to find an actionscript guy here?

Woah, you’re wayy better at coding than I am… I’ve only used about 1/3rd of that.

In this case, the parameter probably won’t help you a ton since you know that the MouseEvent is a “MOUSE_OVER” event but consider the following case where its a KeyboardEvent. The “event” parameter lets you test which keyboard key is being pressed down and perform different actions depending on which it was.

addEventListener(KeyboardEvent.KEY_DOWN, key_pressed);

function key_pressed(event:KeyboardEvent):void {
                        switch(event.keyCode){
				case Keyboard.RIGHT:
					trace("Right arrow key pressed!");
				break;
			
				case Keyboard.LEFT:
					trace("Left arrow key pressed!");
				break;
			}
		}

I’m not really sure why moving it to the second frame fixed your error. Did “servicesmask” exist on that first frame? The error was saying that you were referring to an object which didn’t exist.

Well, get to it! I had already been coding neat stuff for three years at your age.

i’ve got it all figured out. i tried putting all my actionscript onto one frame which has always worked for me in the past. but this time it didn’t work my my particular code.

thanks a ton for helping.

You should be putting as little code as possible into frames, try and keep as much as you can in external AS3 classes. That keeps your code much more modular and expandable. If its in external classes its a lot easier to reuse the code in new projects. You should pick up a book on object oriented actionscript programming.

what book do you recommend?

i created an actionscript file. how do i link those files to a flash project?

ok i figured out how to use an external actionscript file but now i am getting the exact same error.

would debugging help? thing is i don’t know how to debug.