Thursday, March 5, 2009

Error #1009: Cannot access a property or method of a null object reference.

This one gave me quite a bit of trouble.

If you're preloading a .swf and that .swf has classes calling the stage in thier constructor like:
stage.addEventListener(FullScreenEvent.FULL_SCREEN,fullscreenListener);,
the preloader throws an error:

Error #1009: Cannot access a property or method of a null object reference.

The simple fix is to put this in the class constructor:
this.addEventListener(Event.ADDED_TO_STAGE, init);
,
and in the init() function put your call to the stage.

So simple, but it took me a full day to figure out that it was the stage itself (actually a lack of stage) that was causing the error.



No comments:

Post a Comment