Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.

  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

Chapter 12. Events and Event Handling > Event Listeners and Memory Management

12.6. Event Listeners and Memory Management

As we've seen throughout this chapter, ActionScript's event architecture is based on two key participants: the listener (either a function or a method) and the object with which that listener registers. Each object that registers a listener for a given event keeps track of that listener by assigning a reference to it in an internal array known as a listener list. For example, in the following code (repeated from Example 12-1) the completeListener( ) method registers with urlLoader for Event.COMPLETE events. As a result, urlLoader's internal listener list gains a reference to completeListener( ).

package {
  import flash.display.*;
  import flash.net.*;
  import flash.events.*;

  public class FileLoader extends Sprite {
    public function FileLoader () {
      var urlLoader:URLLoader = new URLLoader();
// Register completeListener()
urlLoader.addEventListener(Event.COMPLETE, completeListener);
      urlLoader.load(new URLRequest("someFile.txt"));
    }

    private function completeListener (e:Event):void {
      trace("Load complete");
    }
  }
}


  

You are currently reading a PREVIEW of this book.

                                                                                                                    

Get instant access to over $1 million worth of books and videos.

  

Start a Free 10-Day Trial


  
  • Safari Books Online
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint