[英]How to Load & Unload File SWF at same time
I'm an as3 newbie, i have one button as name tombol
fuctioning to Loading External swf & going to Specific Frame by clicking buttons, this works fine. 我是as3的新手,我有一个按钮作为名称
tombol
功能,可以加载外部SWF文件并通过单击按钮转到“特定帧” ,效果很好。
import flash.events.MouseEvent;
tombol.addEventListener(MouseEvent.CLICK, tekan2);
function tekan2 (e:MouseEvent):void {
function loadSWF(swfURL){
var myLoader:Loader = new Loader();
var mySWF:URLRequest = new URLRequest(swfURL);
myLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, onCompleteHandler);
myLoader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, onProgressHandler);
myLoader.load(mySWF);
}
function onCompleteHandler(loadEvent:Event){
addChild(loadEvent.currentTarget.content);
loadEvent.currentTarget.content.gotoAndStop(swfFrame);
}
function onProgressHandler(myProgress:ProgressEvent){
var percent:Number = Math.round(myProgress.bytesLoaded/myProgress.bytesTotal*100);
trace(percent+"% loaded");
}
var swfFrame:Number=2;
loadSWF("2.swf");
}
This file save as 1.swf and loading file 2.swf go to frame 2, but file 1.swf still loading, so this script loading 2 file swfs(file 2.swf frame 2 loading with file 1.swf appears). 此文件另存为1.swf并加载文件2.swf转到第2帧,但是文件1.swf仍在加载,因此此脚本加载了2个文件swfs(出现了文件2.swf第2帧加载了文件1.swf)。 How to file 1.swf can unloading same time when I click the button, so just file 2.swf frame appears on stage.
当我单击按钮时,如何归档1.swf可以同时卸载,所以只有文件2.swf框架出现在舞台上。
Generally you can cancel a Loader's load operation by using the command close() . 通常,您可以使用命令close()取消加载程序的加载操作。 Before cancelling you need to make sure that the Loader actually loads data, otherwise an Error will be thrown:
取消之前,您需要确保Loader实际加载了数据,否则将引发错误:
if (myLoader.contentLoaderInfo.bytesLoaded > 0 &&
myLoader.contentLoaderInfo.bytesLoaded < myLoader.contentLoaderInfo.bytesTotal)
{
myLoader.cancel();
}
EDIT: You can access the loader of 1.swf by root.loaderInfo . 编辑:您可以通过root.loaderInfo访问1.swf的加载器。 In your function loadSWF you can add the following code to prevent 1.swf from loading further:
您可以在函数loadSWF中添加以下代码,以防止1.swf进一步加载:
if (root.loaderInfo.loader && root.loaderInfo.bytesLoaded > 0 &&
root.loaderInfo.bytesLoaded < root.loaderInfo.bytesTotal)
{
root.loaderInfo.loader.cancel();
}
However, I'm not completely sure if you really can cancel the loading process of 1.swf (I have never tried out something like this). 但是,我不确定您是否真的可以取消1.swf的加载过程(我从未尝试过类似的方法)。 Architecture-wise, it would make sense to have a third SWF file, which is your Main SWF, and loads your other SWF files (1.swf and 2.swf, ...).
从体系结构的角度来看,拥有第三个SWF文件(即您的主SWF文件)并加载其他SWF文件(1.swf和2.swf,...)将很有意义。 In your main SWF you would need to define the Loader as class variable and not as a local variable as you are currently doing.
在主SWF中,您需要将Loader定义为类变量,而不是当前正在定义的局部变量。 Whenever you load a SWF, check if another loading operation is in progress and cancel it in that case.
每当您加载SWF时,请检查是否正在进行其他加载操作,并在这种情况下将其取消。 Ideally, you would place the button tombol in the Main SWF.
理想情况下,您可以将按钮tombol放在Main SWF中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.