MovieClipLoader.loadClip()

可用性

Flash Player 7。

用法

my_mcl.loadMovie("url", target )

参数

url 要加载的 SWF 文件或 JPEG 文件的绝对或相对 URL。相对路径必须相对于级别 0 处的 SWF 文件。绝对 URL 必须包括协议引用,例如 http:// 或 file:///。文件名不能包括磁盘驱动器说明。

target 影片剪辑的目标路径,或者指定 Flash Player 中影片将加载到的级别的整数。目标影片剪辑将替换为加载的影片或图像。

返回

无。

说明

方法;在播放原始影片时,将 SWF 或 JPEG 文件加载到 Flash Player 中的影片剪辑中。使用此方法可以一次显示几个影片并且无需加载另一个 HTML 文档即可在影片间进行切换。

使用此方法(而不是 loadMovie()MovieClip.loadMovie())具有以下若干优点:

加载到影片剪辑的影片或图像会继承该影片剪辑的位置、旋转和缩放属性。可以用该影片剪辑的目标路径来定位加载的影片。

您可以使用此方法将一个或多个文件加载到单个影片剪辑或级别中;将 MovieClipLoader 侦听器对象作为参数传递给正加载的目标影片剪辑实例。或者,您可以为加载的每一文件创建不同的 MovieClipLoader 对象。

使用 MovieClipLoader.unloadClip() 删除用此方法加载的影片或图像,或者取消正在进行中的加载操作。

示例

以下示例举例说明如何使用多个 MovieClipLoader 方法和侦听器。

// 首先设置侦听器
var my_mcl = new MovieClipLoader();
myListener = new Object();
myListener.onLoadStart = function (target_mc) 
{
myTrace ("*********First my_mcl instance*********");
myTrace ("Your load has begun on movie clip .= " + target_mc);
var loadProgress = my_mcl.getProgress(target_mc);
myTrace(loadProgress.bytesLoaded + " = bytes loaded at start");
myTrace(loadProgress.bytesTotal + " = bytes total at start");
}
myListener.onLoadProgress = function (target_mc, loadedBytes, totalBytes) 
{
myTrace ("*********First my_mcl instance Progress*********");
myTrace ("onLoadProgress() called back on movie clip " + target_mc);
myTrace(loadedBytes + " = bytes loaded at progress callback " );
myTrace(totalBytes + " = bytes total at progress callback \n");
}
myListener.onLoadComplete = function (target_mc) 
{
myTrace ("*********First my_mcl instance*********");
myTrace ("Your load is done on movie clip = " + target_mc);
var loadProgress = my_mcl.getProgress(target_mc);
myTrace(loadProgress.bytesLoaded + " = bytes loaded at end" );
myTrace(loadProgress.bytesTotal + " = bytes total at end=");
}
myListener.onLoadInit = function (target_mc) 
{
myTrace ("*********First my_mcl instance*********");
myTrace ("Movie clip = " + target_mc + " is now initialized");
// 您现在可以进行所需的任何设置,例如:
target_mc._width = 100;
target_mc._width = 100;
} 
myListener.onLoadError = function (target_mc, errorCode) 
{
myTrace ("*********First my_mcl instance*********");
myTrace ("ERROR CODE = " + errorCode);
myTrace ("Your load failed on movie clip = " + target_mc + "\n");
 } 
my_mcl.addListener(myListener);
//现在将这些文件加载到其目标中。
// 加载到影片剪辑中 - 字符串用作目标
my_mcl.loadClip("http://www.somedomain.somewhere.com/someFile.swf","_root.myMC");
my_mcl.loadClip("http://www.somedomain.somewhere.com/someOtherFile.swf", "_level0.myMC2");
//失败的加载
my_mcl.loadClip("http://www.somedomain.somewhere.com/someFile.jpg", _root.myMC5);

// 加载到影片剪辑中 - 影片剪辑实例用作目标。
my_mcl.loadClip("http://www.somedomain.somewhere.com/someOtherFile.jpg", _level0.myMC3);

// 加载到 _level1 
my_mcl.loadClip("file:///C:/media/images/somePicture.jpg", 1); 
 
//第二次设置侦听器
var another_mcl = new MovieClipLoader();
myListener2 = new Object();
myListener2.onLoadStart = function (target_mc) 
{
myTrace("*********Second my_mcl instance*********");
myTrace ("Your load has begun on movie clip22 .= " + target_mc);
var loadProgress = my_mcl.getProgress(target_mc);
myTrace(loadProgress.bytesLoaded + " = bytes loaded at start" );
myTrace(loadProgress.bytesTotal + " = bytes total at start");
}
myListener2.onLoadComplete = function (target_mc) 
{
myTrace ("*********Second my_mcl instance*********");
myTrace ("Your load is done on movie clip = " + target_mc);
var loadProgress = my_mcl.getProgress(target_mc);
myTrace(loadProgress.bytesLoaded + " = bytes loaded at end");
myTrace(loadProgress.bytesTotal + " = bytes total at end" );
} 
myListener2.onLoadError = function (target_mc, errorCode) 
{
myTrace ("*********Second my_mcl instance*********");
myTrace ("ERROR CODE = " + errorCode);
myTrace ("Your load failed on movie clip = " + target_mc + "\n");
 } 
another_mcl.addListener(myListener2);
//现在将这些文件加载到其目标中(使用 MovieClipLoader 的第二个实例)
another_mcl.loadClip("http://www.somedomain.somewhere.com/yetAnotherFile.jpg", _root.myMC4);
// 在完成下载以及已调用 my_mcl.onLoadInit 后
// 发出以下语句。
// my_mcl.removeListener(myListener)
// my_mcl.removeListener(myListener2)

另请参见

MovieClipLoader.unloadClip()