AS3 Pitfalls - Error #1009
PROBLEM:
TypeError: Error #1009: Cannot access a property or method of a null object reference.
SOLUTION:
i don’t know.
Error #1009 seems to be catch-all error that Flash throws whenever you reference something that doesn’t “exist”, or hasn’t been loaded into memory. A quick Google search shows that the error spans both Flash and Flex, and can crop up in a number of hair-pulling situations. Here’s the recipe i followed to produce my very own Error #1009 while building a multi-user chat application with ElectroServer 4:
1. i create a document class called Main.as and linked to it from the Flash IDE.
2. i set up my Flash swf with two frames. Frame 1 has a Login widget.

Frame 1. Nothing fancy.
3. Frame 2 has a Chat window, a Send button, and a List component labelled “Users”. The List component’s instance name was userListClip.

Frame 2. Note the “Users” List component on the right.
4. Once the player logs in, i tell the swf to gotoAndStop(2);
5. Now i try to populate my List component, userListClip, with the user names of the people in the chat. No good - dreaded Error #1009 rears its ugly head.
After a bit of research, i read somewhere that my code cannot manipulate objects that i’ve placed on the stage further along the timeline, because those objects have to “exist” at the moment my code is compiled. Huh. Really?
CRUMMY SOLUTION #1 - Alpha/Siberia
One solution is to have that troublesome userListClip instance exist on Frame 1, but drag it off the stage or set it to alpha 0%. This is a very clunky workaround and i don’t like it.
CRUMMY SOLUTION #2 - Clunky Listener
Someone in a Flash user group suggested i register a listener with Event.ADDED. Here’s how that goes:
addListnener(Event.ADDED, onAdded);
private function onAdded(e:Event):void { var clipName:String = e.target.name; switch (clipName) { case "userListClip": populateUserList(); break; default: break; } }//onAdded()
No WAY. That can’t possibly be a respectable solution. Let’s just say it’s “inelegant” and leave it at that. And for some strange reason, my userListClip instance doesn’t ever show up in this function. What gives? Do components not trigger Event.ADDED?
CRUMMY SOLUTION #3 - The Hands-Off Approach
Another solution, obviously, is to build the userListClip List component out of code. i’m resistant to that because i’m one of these hands-on designer types who likes to see what he’s building. i don’t like the fact that my whole design exists in this ethereal, unimaginable codespace that exists only in my darkest desires until compile time.
Not only that, but pure code solutions become a pain to troubleshoot months down the road. i’d much rather see something on the stage and click on it to see its instance name, than to pour through pages and pages of code trying to learn the programmer’s naming convention (even if the programmer is me. i have a lousy memory).
THE BEST SOLUTION
If you’ve generated Error #1009 and have lived to tell about it, please post your solution!







HEheehehehehe…
I have the SAME problem too but i don“t know any ellegant metod to solve this, but i liked the funny way you told us about this fuckin shit horrorible problem =]
I have been having this problem for some time. My usual solution was to set the alpha to zero. But recently I have been using removeEventListener’s to some success.
I.E.
var score1:int = 0;
addEventListener(Event.ENTER_FRAME,whatever); //creating a random event listener
function whatever (e:Event):void {
if(ball.hitTestObject(wall)==true) {
score1++; //if hittest then score goes up by 1
}
if(score1==20) {
removeEventListener(Event.ENTER_FRAME, whatever);
gotoAndStop(2);
//if score1 is equal to 20, then go to and play the second frame. The difference is with the remove event listener, the list clip is removed. This is only happening in the if statement, so it wont effect the movie.
}
}
-spence