MovieClipLoader


Object   |   +-MovieClipLoader public class MovieClipLoader extends Object

This class lets you implement listener callbacks that provide status information while SWF, JPEG, GIF, and PNG files are being loaded into movie clips. To use MovieClipLoader features, use MovieClipLoader.loadClip() instead of loadMovie() or MovieClip.loadMovie() to load SWF files.

After you issue the MovieClipLoader.loadClip() command, the following events take place in the order listed:

  • When the first bytes of the downloaded file have been written to the hard disk, the MovieClipLoader.onLoadStart listener is invoked.

  • If you have implemented the MovieClipLoader.onLoadProgress listener, it is invoked during the loading process.

    Note:You can call MovieClipLoader.getProgress() at any time during the load process.

  • When the entire downloaded file has been written to the hard disk, the MovieClipLoader.onLoadComplete listener is invoked.

  • When the downloaded file's first frame actions have been executed, the MovieClipLoader.onLoadInit listener is invoked.

When MovieClipLoader.onLoadInit has been invoked, you can set properties, use methods, and otherwise interact with the loaded movie.

If the file fails to load completely, the MovieClipLoader.onLoadError listener is invoked.

Availability:ActionScript 1.0; Flash Player 7

Property summary

Properties inherited from class Object

constructor (Object.constructor property) ,__proto__ (Object.__proto__ property),prototype (Object.prototype property) ,__resolve (Object.__resolve property)


Event summary

Event

Description

onLoadComplete = function([target_mc:MovieClip], [httpStatus:Number]) {}

Invoked when a file that was loaded with MovieClipLoader.loadClip() is completely downloaded.

onLoadError = function(target_mc:MovieClip, errorCode:String, [httpStatus:Number]) {}

Invoked when a file loaded with MovieClipLoader.loadClip() has failed to load.

onLoadInit = function([target_mc:MovieClip]) {}

Invoked when the actions on the first frame of the loaded clip have been executed.

onLoadProgress = function([target_mc:MovieClip], loadedBytes:Number, totalBytes:Number) {}

Invoked every time the loading content is written to the hard disk during the loading process (that is, between MovieClipLoader.onLoadStart and MovieClipLoader.onLoadComplete).

onLoadStart = function([target_mc:MovieClip]) {}

Invoked when a call to MovieClipLoader.loadClip() has begun to download a file.


Constructor summary

Signature

Description

MovieClipLoader ()

Creates a MovieClipLoader object that you can use to implement a number of listeners to respond to events while a SWF, JPEG, GIF, or PNG file is downloading.


Method summary

Modifiers

Signature

Description

 

addListener (listener:Object) : Boolean

Registers an object to receive notification when a MovieClipLoader event handler is invoked.

 

getProgress (target:Object) : Object

Returns the number of bytes loaded and the total number of bytes of a file that is being loaded by using MovieClipLoader.loadClip(); for compressed movies, returns the number of compressed bytes.

 

loadClip (url:String, target:Object) : Boolean

Loads a SWF, JPEG, progressive JPEG, unanimated GIF, or PNG file into a movie clip in Flash Player while the original movie is playing.

 

removeListener(listener:Object) : Boolean

Removes the listener that was used to receive notification when a MovieClipLoader event handler was invoked.

 

unloadClip (target:Object) : Boolean

Removes a movie clip that was loaded by using MovieClipLoader.loadClip().


Methods inherited from class Object

addProperty (Object.addProperty method), hasOwnProperty (Object.hasOwnProperty method), isPropertyEnumerable (Object.isPropertyEnumerable method), isPrototypeOf (Object.isPrototypeOf method), registerClass (Object.registerClass method),toString (Object.toString method), unwatch (Object.unwatch method),valueOf (Object.valueOf method), watch (Object.watch method)


addListener (MovieClipLoader.addListener method)

public addListener(listener:Object) : Boolean

Registers an object to receive notification when a MovieClipLoader event handler is invoked.

Availability: ActionScript 1.0; Flash Player 7

Parameters

listener:Object - An object that listens for a callback notification from the MovieClipLoader event handlers.

Returns

Boolean - A Boolean value. Returns true if the listener was established successfully; otherwise false.

Example

The following example loads an image into a movie clip called image_mc. The movie clip instance is rotated and centered on the Stage, and both the Stage and movie clip have a stroke drawn around their perimeters.

this.createEmptyMovieClip("image_mc", this.getNextHighestDepth()); var mclListener:Object = new Object(); mclListener.onLoadInit = function(target_mc:MovieClip) {   target_mc._x = Stage.width/2-target_mc._width/2;   target_mc._y = Stage.height/2-target_mc._width/2;   var w:Number = target_mc._width;   var h:Number = target_mc._height;   target_mc.lineStyle(4, 0x000000);   target_mc.moveTo(0, 0);   target_mc.lineTo(w, 0);   target_mc.lineTo(w, h);   target_mc.lineTo(0, h);   target_mc.lineTo(0, 0);   target_mc._rotation = 3; }; var image_mcl:MovieClipLoader = new MovieClipLoader(); image_mcl.addListener(mclListener); image_mcl.loadClip("http://www.helpexamples.com/flash/images/image1.jpg",   image_mc);

If your SWF file includes a version 2 component, use the version 2 component's DepthManager class instead of the MovieClip.getNextHighestDepth() method, which is used in this example.

See also

onLoadComplete (MovieClipLoader.onLoadComplete event listener), onLoadError (MovieClipLoader.onLoadError event listener),onLoadInit (MovieClipLoader.onLoadInit event listener),onLoadProgress (MovieClipLoader.onLoadProgress event listener),onLoadStart (MovieClipLoader.onLoadStart event listener),removeListener (MovieClipLoader.removeListener method)

getProgress (MovieClipLoader.getProgress method)

public getProgress(target:Object) : Object

Returns the number of bytes loaded and the total number of bytes of a file that is being loaded by using MovieClipLoader.loadClip(); for compressed movies, returns the number of compressed bytes. The getProgress method lets you explicitly request this information, instead of (or in addition to) writing a MovieClipLoader.onLoadProgress listener function.

Availability:ActionScript 1.0; Flash Player 7

Parameters

target:Object - A SWF, JPEG, GIF, or PNG file that is loaded by using MovieClipLoader.loadClip().

Returns

Object - An object that has two integer properties: bytesLoaded and bytesTotal.

Example

The following example demonstrates the use of the getProgress() method. Rather than using this method, you will usually create a listener object to listen for the onLoadProgress event. Also note that the first, synchronous call to getProgress() can return the number of bytes loaded and the total number of bytes of the container and not the values for the externally requested object.

var container:MovieClip = this.createEmptyMovieClip("container",   this.getNextHighestDepth()); var image:MovieClip = container.createEmptyMovieClip("image",   container.getNextHighestDepth()); var mcLoader:MovieClipLoader = new MovieClipLoader(); var listener:Object = new Object(); listener.onLoadProgress = function(target:MovieClip, bytesLoaded:Number,   bytesTotal:Number):Void {   trace(target + ".onLoadProgress with " + bytesLoaded + " bytes of " +   bytesTotal); } mcLoader.addListener(listener); mcLoader.loadClip("http://www.w3.org/Icons/w3c_main.png", image); var interval:Object = new Object(); interval.id = setInterval(checkProgress, 100, mcLoader, image, interval); function checkProgress(mcLoader:MovieClipLoader, image:MovieClip,   interval:Object):Void {   trace(">> checking progress now with : " + interval.id);   var progress:Object = mcLoader.getProgress(image);   trace("bytesLoaded: " + progress.bytesLoaded + " bytesTotal: " +   progress.bytesTotal);   if(progress.bytesLoaded == progress.bytesTotal) {     clearInterval(interval.id);   } }

If your SWF file includes a version 2 component, use the version 2 component's DepthManager class instead of the MovieClip.getNextHighestDepth() method, which is used in this example.

See also

loadClip (MovieClipLoader.loadClip method),onLoadProgress (MovieClipLoader.onLoadProgress event listener)

loadClip (MovieClipLoader.loadClip method)

public loadClip(url:String, target:Object) : Boolean

Loads a SWF, JPEG, progressive JPEG, unanimated GIF, or PNG file into a movie clip in Flash Player while the original movie is playing. If you load an animated GIF, only the first frame is displayed. Using this method you can display several SWF files at once and switch between SWF files without loading another HTML document.

Using the loadClip() method instead of loadMovie() or MovieClip.loadMovie() has a number of advantages. The following handlers are implemented by the use of a listener object. You activate the listener by registering it with the MovieClipLoader class by using MovieClipLoader.addListener(listenerObject).

  • The MovieClipLoader.onLoadStart handler is invoked when loading begins.

  • The MovieClipLoader.onLoadError handler is invoked if the clip cannot be loaded.

  • The MovieClipLoader.onLoadProgress handler is invoked as the loading process progresses.

  • The MovieClipLoader.onLoadComplete handler is invoked when a file completes downloading, but before the loaded movie clip's methods and properties are available. This handler is called before the onLoadInit handler.

  • The MovieClipLoader.onLoadInit handler is invoked after the actions in the first frame of the clip have executed, so you can begin manipulating the loaded clip. This handler is called after the onLoadComplete handler. For most purposes, use the onLoadInit handler.

A SWF file or image loaded into a movie clip inherits the position, rotation, and scale properties of the movie clip. You can use the target path of the movie clip to target the loaded movie.

You can use the loadClip() method to load one or more files into a single movie clip or level; MovieClipLoader listener objects are passed to the loading target movie clip instance as parameters. Alternatively, you can create a different MovieClipLoader object for each file that you load.

Use MovieClipLoader.unloadClip() to remove movies or images loaded with this method or to cancel a load operation that is in progress.

MovieClipLoader.getProgress() and MovieClipLoaderListener.onLoadProgress do not report the actual bytesLoaded and bytesTotal values in the authoring player when the files are local. When you use the Bandwidth Profiler feature in the authoring environment, MovieClipLoader.getProgress() and MovieClipLoaderListener.onLoadProgress report the download at the actual download rate, not at the reduced bandwidth rate that the Bandwidth Profiler provides.

When using this method, consider the Flash Player security model.

For Flash Player 8:

  • Loading is not allowed if the calling movie clip is in the local-with-file-system sandbox and the loaded movie clip is from a network sandbox.

  • Loading is not allowed if the calling SWF file is in a network sandbox and the movie clip to be loaded is local.

  • Network sandbox access from the local-trusted or local-with-networking sandbox requires permission from the website by means of a cross-domain policy file.

  • Movie clips in the local-with-file-system sandbox may not script movie clips in the local-with-networking sandbox (and the reverse is also prevented).

For Flash Player 7 and later:

  • Websites can permit cross-domain access to a resource by means of a cross-domain policy file.

  • Scripting between SWF files is restricted based on the origin domain of the SWF files. Use the System.security.allowDomain() method to adjust these restrictions.

For more information, see the following:

  • Chapter 17, "Understanding Security," in Learning ActionScript 2.0 in Flash

  • The Flash Player 8 Security white paper at http://www.macromedia.com/go/fp8_security

  • The Flash Player 8 Security-Related API white paper at http://www.macromedia.com/go/fp8_security_apis

Availability: ActionScript 1.0; Flash Player 7 - Support for unanimated GIF files, PNG files, and progressive JPEG files is available as of Flash Player 8.

Parameters

url:String - The absolute or relative URL of the SWF, JPEG, GIF, or PNG file to be loaded. A relative path must be relative to the SWF file at level 0. Absolute URLs must include the protocol reference, such as http:// or file:///. Filenames cannot include disk drive specifications.

target:Object - The target path of a movie clip, or an integer specifying the level in Flash Player into which the movie will be loaded. The target movie clip is replaced by the loaded SWF file or image.

Returns

Boolean - A Boolean value. Returns true if the URL request was sent successfully; otherwise false.

Example

The following example shows how to use the MovieClipLoader.loadClip() method by creating a handler for the onLoadInit event and then making the request.

You should either place the following code directly into a frame action on a Timeline, or paste it into a class that extends MovieClip. This code also expects an image named YourImage.jpg to exist in the same directory as the compiled SWF file.

var container:MovieClip = createEmptyMovieClip("container",   getNextHighestDepth()); var mcLoader:MovieClipLoader = new MovieClipLoader(); mcLoader.addListener(this); mcLoader.loadClip("YourImage.jpg", container); function onLoadInit(mc:MovieClip) {   trace("onLoadInit: " + mc); }

If your SWF file includes a version 2 component, use the version 2 component's DepthManager class instead of the MovieClip.getNextHighestDepth() method, which is used in this example.

See also

onLoadInit (MovieClipLoader.onLoadInit event listener)

MovieClipLoader constructor

public MovieClipLoader()

Creates a MovieClipLoader object that you can use to implement a number of listeners to respond to events while a SWF, JPEG, GIF, or PNG file is downloading.

Availability: ActionScript 1.0; Flash Player 7

Example

See MovieClipLoader.loadClip().

See also

addListener (MovieClipLoader.addListener method), loadClip (MovieClipLoader.loadClip method)

onLoadComplete (MovieClipLoader.onLoadComplete event listener)

onLoadComplete = function([target_mc:MovieClip], [httpStatus:Number]) {}

Invoked when a file that was loaded with MovieClipLoader.loadClip() is completely downloaded. Call this listener on a listener object that you add using MovieClipLoader.addListener(). The onLoadComplete event listener is passed by Flash Player to your code, but you do not have to implement all of the parameters in the listener function. The value for target_mc identifies the movie clip for which this call is being made. This identification is useful when multiple files are being loaded with the same set of listeners.

In Flash Player 8, this listener can return an HTTP status code. If Flash Player cannot get the status code from the server, or if Flash Player cannot communicate with the server, the default value of 0 is passed to your ActionScript code. A value of 0 can be generated in any player (for example, if a malformed URL is requested), and a value of 0 is always generated by the Flash Player plug-in when run in the following browsers, which cannot pass HTTP status codes from the server to Flash Player: Netscape, Mozilla, Safari, Opera, and Internet Explorer for the Macintosh.

It's important to understand the difference between MovieClipLoader.onLoadComplete and MovieClipLoader.onLoadInit. The onLoadComplete event is called after the SWF, JPEG, GIF, or PNG file loads, but before the application is initialized. At this point, it is impossible to access the loaded movie clip's methods and properties, and therefore you cannot call a function, move to a specific frame, and so on. In most situations, it's better to use the onLoadInit event instead, which is called after the content is loaded and fully initialized.

Availability: ActionScript 1.0; Flash Player 7 - Support for unanimated GIF files, PNG files, and progressive JPEG files is available as of Flash Player 8.

Parameters

target_mc:MovieClip [optional] - A movie clip loaded by the MovieClipLoader.loadClip() method.

httpStatus:Number [optional] - (Flash Player 8 only) The HTTP status code returned by the server. For example, a status code of 404 indicates that the server has not found anything matching the requested URI. For more information about HTTP status codes, see sections 10.4 and 10.5 of the HTTP specification at ftp://ftp.isi.edu/in-notes/rfc2616.txt.

Example

The following example creates a movie clip, a new MovieClipLoader instance, and an anonymous event listener which listens for the onLoadComplete event but waits for an onLoadInit event to interact with the loaded element properties.

var loadListener:Object = new Object(); loadListener.onLoadComplete = function(target_mc:MovieClip,   httpStatus:Number):Void {   trace(">> loadListener.onLoadComplete()");   trace(">> =============================");   trace(">> target_mc._width: " + target_mc._width); // 0   trace(">> httpStatus: " + httpStatus); } loadListener.onLoadInit = function(target_mc:MovieClip):Void {   trace(">> loadListener.onLoadInit()");   trace(">> =============================");   trace(">> target_mc._width: " + target_mc._width); // 315 } var mcLoader:MovieClipLoader = new MovieClipLoader(); mcLoader.addListener(loadListener); var mc:MovieClip = this.createEmptyMovieClip("mc",   this.getNextHighestDepth()); mcLoader.loadClip("http://www.w3.org/Icons/w3c_main.png", mc);

If your SWF file includes a version 2 component, use the version 2 component's DepthManager class instead of the MovieClip.getNextHighestDepth() method, which is used in this example.

See also

addListener (MovieClipLoader.addListener method), loadClip (MovieClipLoader.loadClip method),onLoadStart (MovieClipLoader.onLoadStart event listener),onLoadError (MovieClipLoader.onLoadError event listener), onLoadInit (MovieClipLoader.onLoadInit event listener)

onLoadError (MovieClipLoader.onLoadError event listener)

onLoadError = function(target_mc:MovieClip, errorCode:String,   [httpStatus:Number]) {}

Invoked when a file loaded with MovieClipLoader.loadClip() has failed to load. This listener can be invoked for various reasons; for example, if the server is down, the file is not found, or a security violation occurs.

Call this listener on a listener object that you add by using

MovieClipLoader.addListener().

The value of target_mc identifies the movie clip for which this call is being made. This parameter is useful if you are loading multiple files with the same set of listeners.

For the errorCode parameter, the string "URLNotFound" is returned if neither the MovieClipLoader.onLoadStart or MovieClipLoader.onLoadComplete listener has been called; for example, if a server is down or the file is not found. The string "LoadNeverCompleted" is returned if MovieClipLoader.onLoadStart was called but MovieClipLoader.onLoadComplete was not called; for example, if the download was interrupted because of server overload, server crash, and so on.

In Flash Player 8, this listener can return an HTTP status code in the httpStatus parameter. If Flash Player cannot get a status code from the server, or if Flash Player cannot communicate with the server, the default value of 0 is passed to your ActionScript code. A value of 0 can be generated in any player (for example, if a malformed URL is requested), and a value of 0 is always generated by the Flash Player plug-in when run in the following browsers, which cannot pass HTTP status codes from the server to Flash Player: Netscape, Mozilla, Safari, Opera, and Internet Explorer for the Macintosh. A value of 0 can also be generated if the player did not try to make the URL request to perform the load operation. This can happen because the request violates security sandbox rules for the SWF file.

Availability: ActionScript 1.0; Flash Player 7

Parameters

target_mc:MovieClip - A movie clip loaded by the MovieClipLoader.loadClip() method.

errorCode:String - A string that explains the reason for the failure, either "URLNotFound" or "LoadNeverCompleted".

httpStatus:Number [optional] - (Flash Player 8 only) The HTTP status code returned by the server. For example, a status code of 404 indicates that the server has not found anything that matches the requested URI. For more information about HTTP status codes, see sections 10.4 and 10.5 of the HTTP specification at ftp://ftp.isi.edu/in-notes/rfc2616.txt.

Example

The following example displays information in the Output panel when an image fails to load. The URL used in this example is for demonstration purposes only; replace it with your own valid URL.

var loadListener:Object = new Object(); loadListener.onLoadError = function(target_mc:MovieClip, errorCode:String,   httpStatus:Number) {   trace(">> loadListener.onLoadError()");   trace(">> ==========================");   trace(">> errorCode: " + errorCode);   trace(">> httpStatus: " + httpStatus); } var mcLoader:MovieClipLoader = new MovieClipLoader(); mcLoader.addListener(loadListener); var mc:MovieClip = this.createEmptyMovieClip("mc",   this.getNextHighestDepth()); mcLoader.loadClip("http://www.fakedomain.com/images/bad_hair_day.jpg", mc);

If your SWF file includes a version 2 component, use the version 2 component's DepthManager class instead of the MovieClip.getNextHighestDepth() method, which is used in this example.

See also

addListener (MovieClipLoader.addListener method), loadClip (MovieClipLoader.loadClip method), onLoadStart (MovieClipLoader.onLoadStart event listener), onLoadComplete (MovieClipLoader.onLoadComplete event listener)

onLoadInit (MovieClipLoader.onLoadInit event listener)

onLoadInit = function([target_mc:MovieClip]) {}

Invoked when the actions on the first frame of the loaded clip have been executed. When this listener has been invoked, you can set properties, use methods, and otherwise interact with the loaded movie. Call this listener on a listener object that you add by using MovieClipLoader.addListener().

The value for target_mc identifies the movie clip for which this call is being made. This parameter is useful if you are loading multiple files with the same set of listeners.

Availability: ActionScript 1.0; Flash Player 7

Parameters

target_mc:MovieClip [optional] - A movie clip loaded by the MovieClipLoader.loadClip() method.

Example

The following example loads an image into a movie clip instance called image_mc. The onLoadInit and onLoadComplete events are used to determine how long it takes to load the image. This information is displayed in a text field called timer_txt.

this.createEmptyMovieClip("image_mc", this.getNextHighestDepth()); var mclListener:Object = new Object(); mclListener.onLoadStart = function(target_mc:MovieClip) {   target_mc.startTimer = getTimer(); }; mclListener.onLoadComplete = function(target_mc:MovieClip) {   target_mc.completeTimer = getTimer(); }; mclListener.onLoadInit = function(target_mc:MovieClip) {   var timerMS:Number = target_mc.completeTimer-target_mc.startTimer;   target_mc.createTextField("timer_txt", target_mc.getNextHighestDepth(),   0, target_mc._height, target_mc._width, 22);   target_mc.timer_txt.text = "loaded in "+timerMS+" ms."; }; var image_mcl:MovieClipLoader = new MovieClipLoader(); image_mcl.addListener(mclListener); image_mcl.loadClip("http://www.helpexamples.com/flash/images/image1.jpg",   image_mc);

The following example checks whether a movie has loaded into a movie clip created at runtime. The URL used in this example is for demonstration purposes only; replace it with your own valid URL.

this.createEmptyMovieClip("tester_mc", 1); var mclListener:Object = new Object(); mclListener.onLoadInit = function(target_mc:MovieClip) {   trace("movie loaded"); } var image_mcl:MovieClipLoader = new MovieClipLoader(); image_mcl.addListener(mclListener); image_mcl.loadClip("http://www.yourserver.com/your_movie.swf", tester_mc);

If your SWF file includes a version 2 component, use the version 2 component's DepthManager class instead of the MovieClip.getNextHighestDepth() method, which is used in this example.

See also

addListener (MovieClipLoader.addListener method), loadClip (MovieClipLoader.loadClip method), onLoadStart (MovieClipLoader.onLoadStart event listener)

onLoadProgress (MovieClipLoader.onLoadProgress event listener)

onLoadProgress = function([target_mc:MovieClip], loadedBytes:Number,   totalBytes:Number) {}

Invoked every time the loading content is written to the hard disk during the loading process (that is, between MovieClipLoader.onLoadStart and MovieClipLoader.onLoadComplete). Call this listener on a listener object that you add by using MovieClipLoader.addListener(). You can use this method to display information about the progress of the download, by using the loadedBytes and totalBytes Parameters.

The value for target_mc identifies the movie clip for which this call is being made. This is useful when you are loading multiple files with the same set of listeners.

Note

If you attempt to use onloadProgress in test mode with a local file that resides on your hard disk, it does not work properly because, in test mode, Flash Player loads local files in their entirety.


Availability: ActionScript 1.0; Flash Player 7

Parameters

target_mc:MovieClip [optional] - A movie clip loaded by the MovieClipLoader.loadClip() method.

loadedBytes:Number - The number of bytes that had been loaded when the listener was invoked.

totalBytes:Number - The total number of bytes in the file being loaded.

Example

The following example creates a movie clip, a new MovieClipLoader instance, and an anonymous event listener. It periodically outputs the progress of a load and finally provides notification when the load is complete and the asset is available to ActionScript.

var container:MovieClip = this.createEmptyMovieClip("container",   this.getNextHighestDepth()); var mcLoader:MovieClipLoader = new MovieClipLoader(); var listener:Object = new Object(); listener.onLoadProgress = function(target:MovieClip, bytesLoaded:Number,   bytesTotal:Number):Void {   trace(target + ".onLoadProgress with " + bytesLoaded + " bytes of " +   bytesTotal); } listener.onLoadInit = function(target:MovieClip):Void {   trace(target + ".onLoadInit"); } mcLoader.addListener(listener); mcLoader.loadClip("http://www.w3.org/Icons/w3c_main.png", container);

If your SWF file includes a version 2 component, use the version 2 component's DepthManager class instead of the MovieClip.getNextHighestDepth() method, which is used in this example.

See also

addListener (MovieClipLoader.addListener method), loadClip (MovieClipLoader.loadClip method), getProgress (MovieClipLoader.getProgress method)

onLoadStart (MovieClipLoader.onLoadStart event listener)

onLoadStart = function([target_mc:MovieClip]) {}

Invoked when a call to MovieClipLoader.loadClip() has begun to download a file. Call this listener on a listener object that you add by using MovieClipLoader.addListener().

The value for target_mc identifies the movie clip for which this call is being made. This parameter is useful if you are loading multiple files with the same set of listeners.

Availability: ActionScript 1.0; Flash Player 7

Parameters

target_mc:MovieClip [optional] - A movie clip loaded by the MovieClipLoader.loadClip() method.

Example

The following example loads an image into a movie clip instance called image_mc. The onLoadInit and onLoadComplete events are used to determine how long it takes to load the image. This information is displayed in a text field called timer_txt.

this.createEmptyMovieClip("image_mc", this.getNextHighestDepth()); var mclListener:Object = new Object(); mclListener.onLoadStart = function(target_mc:MovieClip) {   target_mc.startTimer = getTimer(); }; mclListener.onLoadComplete = function(target_mc:MovieClip) {   target_mc.completeTimer = getTimer(); }; mclListener.onLoadInit = function(target_mc:MovieClip) {   var timerMS:Number = target_mc.completeTimer-target_mc.startTimer;   target_mc.createTextField("timer_txt", target_mc.getNextHighestDepth(),   0, target_mc._height, target_mc._width, 22);   target_mc.timer_txt.text = "loaded in "+timerMS+" ms."; }; var image_mcl:MovieClipLoader = new MovieClipLoader(); image_mcl.addListener(mclListener); image_mcl.loadClip("http://www.helpexamples.com/flash/images/image1.jpg",   image_mc);

If your SWF file includes a version 2 component, use the version 2 component's DepthManager class instead of the MovieClip.getNextHighestDepth() method, which is used in this example.

See also

addListener (MovieClipLoader.addListener method),loadClip (MovieClipLoader.loadClip method),onLoadError (MovieClipLoader.onLoadError event listener),onLoadInit (MovieClipLoader.onLoadInit event listener), onLoadComplete (MovieClipLoader.onLoadComplete event listener)

removeListener (MovieClipLoader.removeListener method)

public removeListener(listener:Object) : Boolean

Removes the listener that was used to receive notification when a MovieClipLoader event handler was invoked. No further loading messages will be received.

Availability: ActionScript 1.0; Flash Player 7

Parameters

listener:Object - A listener object that was added by using MovieClipLoader.addListener().

Returns

Boolean - A Boolean value. Returns TRue if the listener was removed successfully; otherwise false.

Example

The following example loads an image into a movie clip, and enables the user to start and stop the loading process using two buttons called start_button and stop_button. When the user starts or stops the progress, information is displayed in the Output panel.

this.createEmptyMovieClip("image_mc", this.getNextHighestDepth()); var mclListener:Object = new Object(); mclListener.onLoadStart = function(target_mc:MovieClip) {   trace("\t onLoadStart"); }; mclListener.onLoadComplete = function(target_mc:MovieClip) {   trace("\t onLoadComplete"); }; mclListener.onLoadError = function(target_mc:MovieClip, errorCode:String) {   trace("\t onLoadError: "+errorCode); }; mclListener.onLoadInit = function(target_mc:MovieClip) {   trace("\t onLoadInit");   start_button.enabled = true;   stop_button.enabled = false; }; var image_mcl:MovieClipLoader = new MovieClipLoader(); // start_button.clickHandler = function() {   trace("Starting...");   start_button.enabled = false;   stop_button.enabled = true;   //   image_mcl.addListener(mclListener);   image_mcl.loadClip("http://www.helpexamples.com/flash/images/   image1.jpg", image_mc); }; stop_button.clickHandler = function() {   trace("Stopping...");   start_button.enabled = true;   stop_button.enabled = false;   //   image_mcl.removeListener(mclListener); }; stop_button.enabled = false;

If your SWF file includes a version 2 component, use the version 2 component's DepthManager class instead of the MovieClip.getNextHighestDepth() method, which is used in this example.

See also

addListener (MovieClipLoader.addListener method)

unloadClip (MovieClipLoader.unloadClip method)

public unloadClip(target:Object) : Boolean

Removes a movie clip that was loaded by using MovieClipLoader.loadClip(). If you issue this command while a movie is loading, MovieClipLoader.onLoadError is invoked.

Availability: ActionScript 1.0; Flash Player 7

Parameters

target:Object - The string or integer that is passed to the corresponding call to my_mcl.loadClip().

Returns

Boolean - A Boolean value. Returns true if the movie clip was removed successfully; otherwise false.

Example

The following example loads an image into a movie clip called image_mc. When you click the movie clip, the movie clip is removed and information is displayed in the Output panel.

this.createEmptyMovieClip("image_mc", this.getNextHighestDepth()); var mclListener:Object = new Object(); mclListener.onLoadInit = function(target_mc:MovieClip) {   target_mc._x = 100;   target_mc._y = 100;   target_mc.onRelease = function() {   trace("Unloading clip...");   trace("\t name: "+target_mc._name);   trace("\t url: "+target_mc._url);   image_mcl.unloadClip(target_mc);   }; }; var image_mcl:MovieClipLoader = new MovieClipLoader(); image_mcl.addListener(mclListener); image_mcl.loadClip("http://www.helpexamples.com/flash/images/image1.jpg",   image_mc);

If your SWF file includes a version 2 component, use the version 2 component's DepthManager class instead of the MovieClip.getNextHighestDepth() method, which is used in this example.

See also

loadClip (MovieClipLoader.loadClip method),onLoadError (MovieClipLoader.onLoadError event listener)



ActionScript 2.0 Language Reference for Macromedia Flash 8
ActionScript 2.0 Language Reference for Macromedia Flash 8
ISBN: 0321384040
EAN: 2147483647
Year: 2004
Pages: 113

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net