User Guide

364 Handling Events
Checking for existing event listeners
The final two methods of the IEventDispatcher interface provide useful information about
the existence of event listeners. The
hasEventListener() method returns true if an event
listener is found for a specific event type on a particular display list object. The
willTrigger() method also returns true if a listener is found for a particular display list
object, but
willTrigger() checks for listeners not only on that display object, but also on all
of that display list objects ancestors for all phases of the event flow.
Error events without listeners
Exceptions, rather than events, are the primary mechanism for error handling in ActionScript
3.0, but exception handling does not work for asynchronous operations such as loading files.
If an error occurs during such an asynchronous operation, Flash Player dispatches an error
event object. If you do not create a listener for the error event, the debugger version of Flash
Player will bring up a dialog box with information about the error. For example, using an
invalid URL when loading a file produces this dialog box in the debugger version of Flash
Player:
Most error events are based on the ErrorEvent class, and as such will have a property named
text that is used to store the error message that Flash Player displays. The two exceptions are
the StatusEvent and NetStatusEvent classes. Both of these classes have a
level property
(
StatusEvent.level and NetStatusEvent.info.level). When the value of the level
property is "
error", these event types are considered to be error events.
An error event will not cause a SWF file to stop running. It will manifest only as a dialog box
on the debugger versions of the browser plug-ins and stand-alone players, as a message in the
output panel in the authoring player, and as an entry in the log file for Adobe Flex Builder 2.
It will not manifest at all in the release versions of Flash Player.