Tải bản đầy đủ (.pdf) (100 trang)

Tài liệu Flash: ActionScript Language Reference- P7 ppt

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (360.66 KB, 100 trang )

MovieClipLoader class 601
Listener summary for the MovieClipLoader class
Constructor for the MovieClipLoader class
Availability
Flash Player 7.
Usage
new MovieClipLoader() : MovieClipLoader
Parameters
None.
Returns
A reference to a MovieClipLoader object.
Description
Constructor; creates a MovieClipLoader object that you can use to implement a number of
listeners to respond to events while a SWF or JPEG file is downloading.
Example
See MovieClipLoader.loadClip().
See also
MovieClipLoader.addListener()
Listener Description
MovieClipLoader.onLoadComplete
Invoked when a file loaded with
MovieClipLoader.loadClip()

has completely downloaded.
MovieClipLoader.onLoadError
Invoked when a file loaded with
MovieClipLoader.loadClip()
has failed to load.
MovieClipLoader.onLoadInit
Invoked when the actions on the first frame of the loaded clip
have been executed.


MovieClipLoader.onLoadProgress
Invoked every time the loading content is written to disk during
the loading process.
MovieClipLoader.onLoadStart
Invoked when a call to
MovieClipLoader.loadClip()
has
successfully begun to download a file.
602 Chapter 2: ActionScript Language Reference
MovieClipLoader.addListener()
Availability
Flash Player 7.
Usage
my_mcl.addListener(listenerObject:Object) : Void
Parameters
listenerObject
An object that listens for a callback notification from the MovieClipLoader
event handlers.
Returns
Nothing.
Description
Method; registers an object to receive notification when a MovieClipLoader event handler
is invoked.
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(" />112x112/box_studio_112x112.jpg", image_mc);
See also
MovieClipLoader.onLoadComplete, MovieClipLoader.onLoadError,
MovieClipLoader.onLoadInit, MovieClipLoader.onLoadProgress,
MovieClipLoader.onLoadStart, MovieClipLoader.removeListener()
MovieClipLoader.getProgress() 603
MovieClipLoader.getProgress()
Availability
Flash Player 7.
Usage
my_mcl.getProgress(target_mc:Object) : Object
Parameters
target_mc
A SWF or JPEG file that is loaded using MovieClipLoader.loadClip().

Returns
An object that has two integer properties:
bytesLoaded
and
bytesTotal
.
Description
Method; returns the number of bytes loaded and total number of bytes for a file that is being
loaded using MovieClipLoader.loadClip(); for compressed movies, it reflects the number of
compressed bytes. This method lets you explicitly request this information, instead of (or in
addition to) writing a MovieClipLoader.onLoadProgress listener function.
Example
The following example loads an image into a draggable, dynamically created movie clip called
image_mc
. The number of bytes loaded and the total number of bytes for the loaded image
display in a dynamically created text field called
filesize_txt
.
this.createEmptyMovieClip("image_mc", this.getNextHighestDepth());
var mclListener:Object = new Object();
mclListener.onLoadInit = function(target_mc:MovieClip) {
target_mc.onPress = function() {
this.startDrag();
};
target_mc.onRelease = function() {
this.stopDrag();
};
var mclProgress:Object = image_mcl.getProgress(target_mc);
target_mc.createTextField("filesize_txt", target_mc.getNextHighestDepth(),
0, target_mc._height, target_mc._width, 22);

target_mc.filesize_txt.text = mclProgress.bytesLoaded+" of
"+mclProgress.bytesTotal+" bytes loaded";
};
var image_mcl:MovieClipLoader = new MovieClipLoader();
image_mcl.addListener(mclListener);
image_mcl.loadClip(" />112x112/box_studio_112x112.jpg", image_mc);
See also
MovieClipLoader.onLoadProgress
604 Chapter 2: ActionScript Language Reference
MovieClipLoader.loadClip()
Availability
Flash Player 7.
Usage
my_mcl.loadClip(url:String, target:Object ) : Boolean
Parameters
url
The absolute or relative URL of the SWF file or JPEG 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
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
A Boolean value. The return value is
true
if the URL request was sent successfully; otherwise the
return value is
false
.

Description
Method; loads a SWF or JPEG file into a movie clip in Flash Player while the original movie is
playing. Using this method lets you display several SWF files at once and switch between SWF
files without loading another HTML document.
Using this method instead of
loadMovie()
or
MovieClip.loadMovie()
has a number of
advantages. The following handlers are implemented by the use on a listener object, which is
registered with the MovieClipLoader class 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.onLoadInit handler is invoked after the actions in the first frame of the
clip have executed, so you can begin manipulating the loaded clip.

The MovieClipLoader.onLoadComplete handler is invoked when a file has completed
downloading.
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 the loading target movie clip instance as a parameter.
Alternately, you can create a different MovieClipLoader object for each file 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.loadClip() 605
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.
Example
The following example illustrates the use of many of the MovieClipLoader class methods and
listeners:
// first set of listeners
var my_mcl:MovieClipLoader = new MovieClipLoader();
var myListener:Object = new Object();
myListener.onLoadStart = function(target_mc:MovieClip) {

trace("*********First my_mcl instance*********");
trace("Your load has begun on movie clip = "+target_mc);
var loadProgress:Object = my_mcl.getProgress(target_mc);
trace(loadProgress.bytesLoaded+" = bytes loaded at start");
trace(loadProgress.bytesTotal+" = bytes total at start");
};
myListener.onLoadProgress = function(target_mc:MovieClip, loadedBytes:Number,
totalBytes:Number) {
trace("*********First my_mcl instance Progress*********");
trace("onLoadProgress() called back on movie clip "+target_mc);
trace(loadedBytes+" = bytes loaded at progress callback");
trace(totalBytes+" = bytes total at progress callback");
};
myListener.onLoadComplete = function(target_mc:MovieClip) {
trace("*********First my_mcl instance*********");
trace("Your load is done on movie clip = "+target_mc);
var loadProgress:Object = my_mcl.getProgress(target_mc);
trace(loadProgress.bytesLoaded+" = bytes loaded at end");
trace(loadProgress.bytesTotal+" = bytes total at end");
};
myListener.onLoadInit = function(target_mc:MovieClip) {
trace("*********First my_mcl instance*********");
trace("Movie clip = "+target_mc+" is now initialized");
// you can now do any setup required, for example:
target_mc._width = 100;
target_mc._height = 100;
};
myListener.onLoadError = function(target_mc:MovieClip, errorCode:String) {
trace("*********First my_mcl instance*********");
trace("ERROR CODE = "+errorCode);

trace("Your load failed on movie clip = "+target_mc+"\n");
};
my_mcl.addListener(myListener);
// Now load the files into their targets.
// loads into movie clips
this.createEmptyMovieClip("clip1_mc", this.getNextHighestDepth());
clip1_mc._x = 400;
this.createEmptyMovieClip("clip2_mc", this.getNextHighestDepth());
606 Chapter 2: ActionScript Language Reference
my_mcl.loadClip("
clip1_mc);
my_mcl.loadClip(" />ben_forta.jpg", clip2_mc);
clip2_mc._x = 200;
// loads into _level1
my_mcl.loadClip(" />mike_chambers.jpg", 1);
//
// Second set of listeners
var another_mcl:MovieClipLoader = new MovieClipLoader();
var myListener2:Object = new Object();
myListener2.onLoadStart = function(target_mc:MovieClip) {
trace("*********Second my_mcl instance*********");
trace("Your load has begun on movie = "+target_mc);
var loadProgress:Object = my_mcl.getProgress(target_mc);
trace(loadProgress.bytesLoaded+" = bytes loaded at start");
trace(loadProgress.bytesTotal+" = bytes total at start");
};
myListener2.onLoadComplete = function(target_mc:MovieClip) {
trace("*********Second my_mcl instance*********");
trace("Your load is done on movie clip = "+target_mc);
var loadProgress:Object = my_mcl.getProgress(target_mc);

trace(loadProgress.bytesLoaded+" = bytes loaded at end");
trace(loadProgress.bytesTotal+" = bytes total at end");
};
myListener2.onLoadError = function(target_mc:MovieClip, errorCode:String) {
trace("*********Second my_mcl instance*********");
trace("ERROR CODE = "+errorCode);
trace("Your load failed on movie clip = "+target_mc+"\n");
};
another_mcl.addListener(myListener2);
/* Now load the files into their targets (using the second instance of
MovieClipLoader) */
another_mcl.loadClip(" />flex_logo.jpg", this.createEmptyMovieClip("clip4_mc",
this.getNextHighestDepth()));
clip4_mc._y = 200;
// Issue the following statements after the download is complete,
// and after my_mcl.onLoadInit has been called.
// my_mcl.removeListener(myListener);
// my_mcl.removeListener(myListener2);
See also
MovieClipLoader.unloadClip()
MovieClipLoader.onLoadComplete 607
MovieClipLoader.onLoadComplete
Availability
Flash Player 7.
Usage
listenerObject.onLoadComplete = function([target_mc:Object]) {
// your statements here
}
Parameters
listenerObject

A listener object that was added using MovieClipLoader.addListener().
target_mc
A movie clip loaded by a MovieClipLoader.loadClip() method. This parameter is
optional.
Returns
Nothing.
Description
Listener; invoked when a file loaded with MovieClipLoader.loadClip() has completely
downloaded. The value for
target_mc
identifies the movie clip for which this call is being made.
This is useful if multiple files are being loaded with the same set of listeners.
This parameter is passed by Flash to your code, but you do not have to implement all of the
parameters in the listener function.
When you use the
onLoadComplete
and
onLoadInit
events with the MovieClipLoader class, it’s
important to understand how this differs from the way they work with your SWF file. The
onLoadComplete
event is called after the SWF or JPEG file has loaded, but before the application
has been initialized. At this point it is impossible to access the loaded movie clip’s methods and
properties, and because of this 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
has loaded and is fully initialized.
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. The information displays in a dynamically created 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;
608 Chapter 2: ActionScript Language Reference
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(" />112x112/box_studio_112x112.jpg", image_mc);
See also
MovieClipLoader.addListener(), MovieClipLoader.onLoadStart,
MovieClipLoader.onLoadError

MovieClipLoader.onLoadError 609
MovieClipLoader.onLoadError
Availability
Flash Player 7.
Usage
listenerObject.onLoadError = function(target_mc:Object, errorCode:String) {
// your statements here
}
Parameters
listenerObject
A listener object that was added using MovieClipLoader.addListener().
target_mc
A movie clip loaded by a MovieClipLoader.loadClip() method.
errorCode
A string that explains the reason for the failure.
Returns
One of two strings:
"URLNotFound"
or
"LoadNeverCompleted"
.
Description
Listener; invoked when a file loaded with MovieClipLoader.loadClip() has failed to load.
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, these listeners are not called.
The string
"LoadNeverCompleted"

is returned if
MovieClipLoader.onLoadStart
was called
but
MovieClipLoader.onLoadComplete
was not called. For example, if
MovieClipLoader.onLoadStart
is called but the download is interrupted due to server
overload, server crash, and so on,
MovieClipLoader.onLoadComplete
will not be called.
The value for
target_mc
identifies the movie clip this call is being made for. This is useful if you
are loading multiple files with the same set of listeners. This optional parameter is passed to your
ActionScript.
Example
The following example displays information in the Output panel when an image fails to load.
This occurs when you test the following ActionScript, because the image does not exist in the
specified location.
this.createEmptyMovieClip("image_mc", this.getNextHighestDepth());
var mclListener:Object = new Object();
mclListener.onLoadError = function(target_mc:MovieClip, errorCode:String) {
trace("ERROR!");
switch (errorCode) {
case 'URLNotFound' :
trace("\t Unable to connect to URL: "+target_mc._url);
break;
case 'LoadNeverCompleted' :
trace("\t Unable to complete download: "+target_mc);

break;
610 Chapter 2: ActionScript Language Reference
}
};
mclListener.onLoadInit = function(target_mc:MovieClip) {
trace("success");
trace(image_mcl.getProgress(target_mc).bytesTotal+" bytes loaded");
};
var image_mcl:MovieClipLoader = new MovieClipLoader();
image_mcl.addListener(mclListener);
image_mcl.loadClip("
image_mc);
MovieClipLoader.onLoadInit 611
MovieClipLoader.onLoadInit
Availability
Flash Player 7.
Usage
listenerObject.onLoadInit = function([target_mc:MovieClip]) {
// your statements here
}
Parameters
listenerObject
A listener object that was added using MovieClipLoader.addListener().
target_mc
A movie clip loaded by a MovieClipLoader.loadClip() method. This parameter is
optional.
Returns
Nothing.
Description
Listener; invoked when the actions on the first frame of the loaded clip have been executed. After

this listener has been invoked, you can set properties, use methods, and otherwise interact with
the loaded movie.
The value for
target_mc
identifies the movie clip this call is being made for. This is useful if you
are loading multiple files with the same set of listeners. This optional parameter is passed to your
ActionScript.
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 displays 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(" />112x112/box_studio_112x112.jpg", image_mc);
612 Chapter 2: ActionScript Language Reference
See also
MovieClipLoader.onLoadStart
MovieClipLoader.onLoadProgress 613
MovieClipLoader.onLoadProgress
Availability
Flash Player 7.
Usage
listenerObject.onLoadProgress =
function([target_mc:Object [, loadedBytes:Number [, totalBytes:Number ] ] ]
) {
// your statements here
}
Parameters
listenerObject
A listener object that was added using MovieClipLoader.addListener().
target_mc
A movie clip loaded by a MovieClipLoader.loadClip() method. This parameter is
optional.
loadedBytes
The number of bytes that had been loaded when the listener was invoked.
totalBytes
The total number of bytes in the file being loaded.
Returns
Nothing.

Description
Listener; invoked every time the loading content is written to disk during the loading process
(that is, between
MovieClipLoader.onLoadStart
and
MovieClipLoader.onLoadComplete
).
You can use this method to display information about the progress of the download, using the
loadedBytes
and
totalBytes
parameters.
The value for
target_mc
identifies the movie clip this call is being made for. This is useful if you
are loading multiple files with the same set of listeners. This optional parameter is passed to your
ActionScript.
Example
The following example creates a progress bar using the Drawing API. The progress bar displays
the loading progress of an image using the
onLoadProgress
listener. When the image finishes
loading, the progress bar is removed from the Stage. You must replace the URL parameter of the
image_mcl.loadClip()
command so that the parameter refers to a valid JPEG file using HTTP.
If you attempt to use this example to load a local file that resides on your hard disk, this example
will not work properly because, in test movie mode, Flash Player loads local files in their entirety.
Add the following ActionScript to your FLA or AS file:
this.createEmptyMovieClip("progressBar_mc", 0);
progressBar_mc.createEmptyMovieClip("bar_mc", 1);

progressBar_mc.createEmptyMovieClip("stroke_mc", 2);
with (progressBar_mc.stroke_mc) {
lineStyle(0, 0x000000);
moveTo(0, 0);
lineTo(100, 0);
614 Chapter 2: ActionScript Language Reference
lineTo(100, 10);
lineTo(0, 10);
lineTo(0, 0);
}
with (progressBar_mc.bar_mc) {
beginFill(0xFF0000, 100);
moveTo(0, 0);
lineTo(100, 0);
lineTo(100, 10);
lineTo(0, 10);
lineTo(0, 0);
endFill();
_xscale = 0;
}
progressBar_mc._x = 2;
progressBar_mc._y = 2;
//
var mclListener:Object = new Object();
mclListener.onLoadStart = function(target_mc:MovieClip) {
progressBar_mc.bar_mc._xscale = 0;
};
mclListener.onLoadProgress = function(target_mc:MovieClip, bytesLoaded:Number,
bytesTotal:Number) {
progressBar_mc.bar_mc._xscale = Math.round(bytesLoaded/bytesTotal*100);

};
mclListener.onLoadComplete = function(target_mc:MovieClip) {
progressBar_mc.removeMovieClip();
};
mclListener.onLoadInit = function(target_mc:MovieClip) {
target_mc._height = 320;
target_mc._width = 240;
};
this.createEmptyMovieClip("image_mc", 100);
var image_mcl:MovieClipLoader = new MovieClipLoader();
image_mcl.addListener(mclListener);
image_mcl.loadClip("[place a valid URL pointing to a JPEG file here]",
image_mc);
See also
MovieClipLoader.getProgress()
MovieClipLoader.onLoadStart 615
MovieClipLoader.onLoadStart
Availability
Flash Player 7.
Usage
listenerObject.onLoadStart = function([target_mc:Object]) {
// your statements here
}
Parameters
listenerObject
A listener object that was added using MovieClipLoader.addListener().
target_mc
A movie clip loaded by a MovieClipLoader.loadClip() method. This parameter is
optional.
Returns

Nothing.
Description
Listener; invoked when a call to MovieClipLoader.loadClip() has successfully begun to download
a file. The value for
target_mc
identifies the movie clip this call is being made for. This is useful
if you are loading multiple files with the same set of listeners. This optional parameter is passed to
your ActionScript.
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 displays 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(" />112x112/box_studio_112x112.jpg", image_mc);
616 Chapter 2: ActionScript Language Reference
See also
MovieClipLoader.onLoadError, MovieClipLoader.onLoadInit,
MovieClipLoader.onLoadComplete
MovieClipLoader.removeListener() 617
MovieClipLoader.removeListener()
Availability
Flash Player 7.
Usage
my_mcl.removeListener(listenerObject:Object) : Void
Parameters
listenerObject
A listener object that was added using MovieClipLoader.addListener().
Returns
Nothing.
Description
Method; removes the listener that was used to receive notification when a
MovieClipLoader

event handler was invoked. No further loading messages will be received.
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(" />flex_logo.jpg", image_mc);
};

stop_button.clickHandler = function() {
trace("Stopping...");
618 Chapter 2: ActionScript Language Reference
start_button.enabled = true;
stop_button.enabled = false;
//
image_mcl.removeListener(mclListener);
};
stop_button.enabled = false;
MovieClipLoader.unloadClip() 619
MovieClipLoader.unloadClip()
Availability
Flash Player 7.
Usage
my_mcl.unloadClip(target:Object)
Parameters
target
The string or integer passed to the corresponding call to
my_mcl.loadClip()
.
Returns
Nothing.
Description
Method; removes a movie clip that was loaded by means of MovieClipLoader.loadClip(). If you
issue this command while a movie is loading, MovieClipLoader.onLoadError is invoked.
Example
The following example loads an image into a movie clip called
image_mc
. If 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(" />flex_logo.jpg", image_mc);
See also
MovieClipLoader.loadClip()
620 Chapter 2: ActionScript Language Reference
NaN
Availability
Flash Player 5.
Usage
NaN
Description
Variable; a predefined variable with the IEEE-754 value for
NaN
(not a number). To determine if
a number is
NaN
, use

isNaN()
.
See also
isNaN(), Number.NaN
CHAPTER 2
ActionScript Language Reference
-Infinity 621
-Infinity
Availability
Flash Player 5.
Usage
-Infinity
Description
Constant; specifies the IEEE-754 value representing negative infinity. The value of this constant
is the same as
Number.NEGATIVE_INFINITY
.
CHAPTER 2
ActionScript Language Reference
622 Chapter 2: ActionScript Language Reference
NetConnection class
Availability
Flash Player 7.
Note: This class is also supported in Flash Player 6 when used with Flash Communication Server.
For more information, see the Flash Communication Server documentation.
Description
The NetConnection class provides the means to play back streaming FLV files from a local drive
or HTTP address. For more information on video playback, see “Playing back external FLV files
dynamically” in Using ActionScript in Flash.
Method summary for the NetConnection class

Constructor for the NetConnection class
Availability
Flash Player 7.
Note: This class is also supported in Flash Player 6 when used with Flash Communication Server.
For more information, see your Flash Communication Server documentation.
Usage
new NetConnection() : NetConnection
Parameters
None.
Returns
A reference to a NetConnection object.
Description
Constructor; creates a NetConnection object that you can use in conjunction with a NetStream
object to play back local streaming video (FLV) files. After creating the NetConnection object,
use NetConnection.connect() to make the actual connection.
Playing external FLV files provides several advantages over embedding video in a Flash document,
such as better performance and memory management, and independent video and Flash frame
rates. For more information on video playback, see “Playing back external FLV files dynamically”
in Using ActionScript in Flash.
Example
See the example for NetConnection.connect().
Method Description
NetConnection.connect()
Opens a local connection through which you can play back video
(FLV) files from an HTTP address or from the local file system.
CHAPTER 2
ActionScript Language Reference
NetConnection class 623
See also
NetStream class, Video.attachVideo()

624 Chapter 2: ActionScript Language Reference
NetConnection.connect()
Availability
Flash Player 7.
Note: This method is also supported in Flash Player 6 when used with Flash Communication Server.
For more information, see the Flash Communication Server documentation.
Usage
my_nc.connect(null) : Void
Parameters
None (you must pass
null
).
Returns
Nothing.
Description
Constructor; opens a local connection through which you can play back video (FLV) files from an
HTTP address or from the local file system.
Example
The following example opens a connection to play the video2.flv file. Select New Video from the
Library panel’s options menu to create a new video object, and give it the instance name
my_video
.
var connection_nc:NetConnection = new NetConnection();
connection_nc.connect(null);
var stream_ns:NetStream = new NetStream(connection_nc);
my_video.attachVideo(stream_ns);
stream_ns.play("video2.flv");
See also
NetStream class
NetStream class 625

NetStream class
Availability
Flash Player 7.
Note: This class is also supported in Flash Player 6 when used with Flash Communication Server.
For more information, see the Flash Communication Server documentation.
Description
The NetStream class provides methods and properties for playing Flash Video (FLV) files from
the local file system or an HTTP address. You use a NetStream object to stream video through a
NetConnection object. Playing external FLV files provides several advantages over embedding
video in a Flash document, such as better performance and memory management, and
independent video and Flash frame rates. This class provides a number of methods and properties
you can use to track the progress of the file as it loads and plays, and to give the user control over
playback (stopping, pausing, and so on).
For more information on video playback, see “Playing back external FLV files dynamically” in
Using ActionScript in Flash.
Method summary for the NetStream class
The following methods and properties of the NetConnection and NetStream classes are used to
control FLV playback.
Property summary for the NetStream class
Method Purpose
NetStream.close()
Closes the stream but does not clear the video object.
NetStream.pause()
Pauses or resumes playback of a stream.
NetStream.play()
Begins playback of an external video (FLV) file.
NetStream.seek()
Seeks a specific position in the FLV file.
NetStream.setBufferTime()
Specifies how long to buffer data before starting to display the stream.

Property Description
NetStream.bufferLength
The number of seconds of data currently in the buffer.
NetStream.bufferTime
Read-only; the number of seconds assigned to the buffer by
NetStream.setBufferTime()
.
NetStream.bytesLoaded
Read-only; the number of bytes of data that have been loaded into
the player.
NetStream.bytesTotal
Read-only; the total size in bytes of the file being loaded into
the player.
NetStream.currentFps
The number of frames per second being displayed.
NetStream.time
Read-only; the position of the playhead, in seconds.
CHAPTER 2
ActionScript Language Reference

×