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

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.

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.macromedia.com/images/shared/product_boxes/
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

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("http://www.macromedia.com/images/shared/product_boxes/
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

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();

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("http://www.macromedia.com/software/drk/images/box_drk5.jpg",
clip1_mc);
my_mcl.loadClip("http://www.macromedia.com/devnet/images/160x160/
ben_forta.jpg", clip2_mc);
clip2_mc._x = 200;
// loads into _level1
my_mcl.loadClip("http://www.macromedia.com/devnet/images/160x160/
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");
};

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

image_mcl.addListener(mclListener);
image_mcl.loadClip("http://www.macromedia.com/images/shared/product_boxes/
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

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("http://www.fakedomain.com/images/bad_hair_day.jpg",
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

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.macromedia.com/images/shared/product_boxes/
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

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;
//

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();

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();
//

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("http://www.macromedia.com/devnet/images/160x160/
flex_logo.jpg", image_mc);
See also
MovieClipLoader.loadClip()
620 Chapter 2: ActionScript Language Reference
NaN
Availability

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

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


Nhờ tải bản gốc

Tài liệu, ebook tham khảo khác

Music ♫

Copyright: Tài liệu đại học © DMCA.com Protection Status