Unusual Flash Error in IE7 and Mac Browsers
This problem only seems to pop up under very specific circumstances, namely, when extending UIComponent as the the document class. However, after scratching my head at this for a while I figured I'd post it just in case somebody sees something similar.
It's also unusual to see Flash player behaving differently on different platforms.
First, the symptoms. The swf worked fine in the Flash movie test and in Firefox but I heard reports from my coworkers that they were getting errors on Macs. Since I don't have ready access to a Mac it was difficult to debug... until we discovered Internet Explorer 7 was having a similar problem (but no error message).
TypeError: Error #1009: Cannot access a property or method of a null object reference.
That's the error message that was showing up on the Mac machines. The error itself isn't unusual but I don't think it gets thrown for this reason very often.
For my document class I extended UIComponent, which listens to the stage's Event.RENDER event for dispatching its callLater methods. It turns out that when you set the stage.align property, the stage throws the render event in IE7 and Safari but not in other platforms we've tested so far. In my document class, I set the stage.align property before instantiating all my DisplayObjects. This results in a call to draw() before all those Sprites and TextFields and MovieClips are setup... null object reference.
The fix? Put a quick test in the draw function to make sure that your DisplayObjects are not null before proceeding.
override protected function draw():void { if (mySprite == null) return; ...
I'd be interested to know if anybody else actually uses UIComponent for the document class. Please drop a comment below!
Delicious
Digg
Reddit
Facebook
Google
Yahoo
Technorati

Comments
Post new comment