3.
Add the following code to Frame 1 of the main Timeline;
System.security.allowDomain("http://www.helpexamples.com");
var loaderListener:Object = new Object();
loaderListener.progress = function(evt_obj:Object):Void {
trace(evt_obj.type); // progress
trace("\t" + evt_obj.target.bytesLoaded + " of " +
evt_obj.target.bytesTotal + " bytes loaded");
}
loaderListener.complete = function(evt_obj:Object):Void {
trace(evt_obj.type); // complete
}
my_ldr.addEventListener("progress", loaderListener);
my_ldr.addEventListener("complete", loaderListener);
my_ldr.load("http://www.helpexamples.com/flash/images/image1.jpg");
This ActionScript code defines a listener object named
two events:
progress
code is executed, and debugging text is displayed in the Output panel if you test the SWF
file in the authoring tool.
Next you tell the
and
) and specify the listener object or function to execute when the event is
complete
dispatched. Finally, the
begin downloading.
4.
Select Control > Test Movie to test the SWF file.
The image downloads into the Loader instance on the Stage, and then several messages are
displayed in the Output panel. Depending on the size of the image you download, and if
the image was cached on the user's local system, the
numerous times, whereas the complete event is only dispatched after the image is
completely downloaded.
When you work with components and dispatch events, the syntax is slightly different
from the event listeners in previous examples. Most notably, you must use the
addEventListener()
specify the specific event you want to listen for as well as the event listener object
or function.
336
Handling Events
and
. When each of these events are dispatched, their
complete
instance to listen for each of the two specified events (
my_ldr
Loader.load()
method instead of calling
loaderListener
method is called, which triggers the image to
progress
addListener()
, which listens for
progress
event might be dispatched
. Secondly, you must
Need help?
Do you have a question about the FLASH 8-LEARNING ACTIONSCRIPT 2.0 IN FLASH and is the answer not in the manual?