我在舞台上有一个按钮,它使用Loader类加载外部SWF。我希望能够在用户点击它外面时,即在舞台上的任何其他位置卸载SWF。
到目前为止,我只有加载SWF的代码......
mybutton.addEventListener(MouseEvent.CLICK, fl_LoadExternalSwf);
function fl_LoadExternalSwf(event:MouseEvent):void
{
var my_Loader:Loader = new Loader();
var my_url:URLRequest=new URLRequest("pageFlip.swf");
//These listeners detect when the file has finished loading, and if the
//correct file is loaded.
my_Loader.contentLoaderInfo.addEventListener(Event.COMPLETE, finishLoading);
my_Loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, errorHandler);
//The load method then loads the SWF file into the loader object.
my_Loader.load(my_url);
//This function adds the external SWF to the stage.
function finishLoading(loadEvent:Event) {
addChild(loadEvent.currentTarget.content);
}
//This function displays a message if the file is not found.
function errorHandler(errorEvent:Event):void {
trace("file missing");
}
}
答案 0 :(得分:0)
您可以使用unload()
类
Loader()
function unloadMC(myLoader:Loader, myURL:URLRequest):void {
myLoader.unLoad(myURL);
}
unloadMC(my_Loader, my_url);
修改强>
您需要一个外部接口来调用“除了”swf之外的click事件。首先,您需要使用jQuery来实现
$(document).bind('click', function (e) {
$('#yourSWFObject').clickOutside();
});
$('#special').bind('click', function(e) {
e.stopPropagation();
});
点击方法。之后,您需要使用
从AS3应用externalInterfaceimport flash.external.ExternalInterface;
public function clickOutside() {
unloadMC(my_Loader, my_url);
}