PDA

View Full Version : flash error 1009


catinabag1
2008-12-27, 04:55 AM
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?

catinabag1
2008-12-27, 05:10 AM
forgot to add, everything works until i add the second mouse event.

catinabag1
2008-12-28, 03:58 AM
bump

Brian O.
2008-12-28, 06:27 AM
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:

function servegone(evt:MouseEvent):void {

gotoAndStop(1);
}

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?

catinabag1
2008-12-28, 06:35 AM
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?

beeper
2008-12-28, 06:38 AM
Woah, you're wayy better at coding than I am.. I've only used about 1/3rd of that.

Brian O.
2008-12-28, 06:57 AM
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.

catinabag1
2008-12-28, 08:15 AM
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.

Brian O.
2008-12-28, 06:10 PM
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.

catinabag1
2008-12-28, 10:33 PM
what book do you recommend?

catinabag1
2008-12-28, 10:58 PM
i created an actionscript file. how do i link those files to a flash project?

catinabag1
2008-12-28, 11:32 PM
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.