Adobe FLEX 2-PROGRAMMING ACTIONSCRIPT 3.0 Manual page 257

Programming actionscript 3.0
Table of Contents

Advertisement

Asynchronous errors are run-time errors that occur at various points during run time; they
generate events and are caught by event listeners. An asynchronous operation is one in
which a function initiates an operation, but doesn't wait for it to complete. You can create
an error event listener to wait for the application or user to try some operation, and if the
operation fails, you catch the error with an event listener and respond to the error event.
Then, the event listener calls an event handler function to respond to the error event in a
useful manner. For example, the event handler could launch a dialog box that prompts the
user to resolve the error.
Consider the file-upload synchronous error example presented earlier. If you successfully
call the
browse()
several events. For example, when an upload starts, the
the file upload operation completes successfully, the
Because event handling is asynchronous (that is, it does not occur at specific, known,
predesignated times), you need to use the
these specific events, as the following code shows:
var fileRef:FileReference = new FileReference();
fileRef.addEventListener(Event.SELECT, selectHandler);
fileRef.addEventListener(Event.OPEN, openHandler);
fileRef.addEventListener(Event.COMPLETE, completeHandler);
fileRef.browse();
function selectHandler(event:Event):void
{
trace("...select...");
var request:URLRequest = new URLRequest("http://www.yourdomain.com/
fileupload.cfm");
request.method = URLRequestMethod.POST;
event.target.upload(request.url);
}
function openHandler(event:Event):void
{
trace("...open...");
}
function completeHandler(event:Event):void
{
trace("...complete...");
}
For detailed information on asynchronous error handling, see
and status" on page
method before beginning a file upload, Flash Player would dispatch
267.
event is dispatched. When
open
complete
addEventListener()
"Responding to error events
event is dispatched.
method to listen for
Types of errors
257

Advertisement

Table of Contents
loading

This manual is also suitable for:

Flex

Table of Contents