AS3 Async is a set of utilities for working with asynchronous code. It has a global method called when() that provides a convenient way of handling Events using closures.


package app.service {
    public class DataLoader extends EventDispatcher {
        private var _url : String;
        private var _parser : IDataParser;

        public function DataLoader(url : String, parser : IDataParser) {
            _url = url;
            _parser = parser;

        public function load() : void {
            const urlLoader : URLLoader = new URLLoader();

            // Create a mapping that will listen for Event.COMPLETE being dispatched by urlLoader.
            when(urlLoader, Event.COMPLETE, function () : void {
                // This code is invoked when the event is fired, because we are inside a closure
                // it can access properties from the parent function and parent Class.
                const data : MyData = _parser.parse(;

                // In this example we dispatch a custom Event to let the rest of the system know 
                // something has happened.
                dispatchEvent(new DataLoadedEvent(DataLoadedEvent.DATA_LOADED, data)); 

            urlLoader.load(new URLRequest(_url));
Misc . URL.