catching async events in as3 that cause errors
I'm using the astra library which is using the fl library.
The problem I have is that I get errors, some reproduce-able, some seemingly random.
I'm relying on a lot of the data being driven by timers, but there are all these UIComponents that one would interact with at the same time.
Problem 1 :
I have a view that has a text area in it, and a a bunch of tabs above. If I'm scrolling the text area while the view jumps to another frame I get the #1009 null object error at fl.controls::ScrollBar/thumbReleaseHandler()
Problem 2 : the second one seems intermittent and I cann开发者_如何学Cot consistently reproduce it, but I'm sure it's liked to the timer redrawing the current tab-view while the user is interacting with it.
TypeError: Error #2007: Parameter child must be non-null.
at flash.display::DisplayObjectContainer/addChildAt()
at fl.controls::BaseButton/drawBackground()
at fl.controls::LabelButton/draw()
at fl.controls::Button/draw()
at fl.core::UIComponent/callLaterDispatcher()
Is there a way to catch these events before they cause the objects to throw these errors?
If you can require Flash Player 10.1, you can try to use the new global exception handling API: http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/events/UncaughtErrorEvents.html
It still doesn't catch all uncaught errors (most notably AS2 errors thrown after being loaded into an AS3 SWF), but it may handle yours.
Other than that, you could sweep through your code and debug these instances. If you're running the debug version of your SWF, you should get line numbers to point you to the offending code. The solution is often to just do a null check, and ignore the action if you don't have a reference to the object.
精彩评论