Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.
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");
}
}
}