简体   繁体   English

外部swf仍在加载到其他场景吗? 如何正确卸载?

[英]External swf still loading to other scenes? How to properly unload?

I have encountered same problem but in different scenario, i have 4 scenes and in my 4th scene i have 3 button inside that loads and unloads external swf. 我遇到了同样的问题,但是在不同的情况下,我有4个场景,在第4个场景中,我有3个内部按钮可以加载和卸载外部swf。 Within the 4th Scene it works perfectly but when i try to hit my main navigation (which links to Scene 1,2 and 3), the external swf is still loading to the other scenes... it's been crazy i've tried lots of method but it's not working. 在第四个场景中,它工作正常,但是当我尝试点击主导航(链接到场景1,2和3)时,外部swf仍在加载到其他场景中……我已经尝试了很多方法,但不起作用。

Here is my script: Scene 4 这是我的脚本:场景4

import flash.display.MovieClip;
import flash.display.Loader;
import flash.net.URLRequest;
import flash.events.MouseEvent;

var Xpos:Number = 525;
var Ypos:Number = 200;
var swf:MovieClip;
var loader:Loader=new Loader();

var defaultSWF:URLRequest=new URLRequest("Steps/intro.swf");


loader.load(defaultSWF);
loader.x = Xpos;
loader.y = Ypos;
addChild(loader);
//button function 
function btnCLICK(event:MouseEvent):void{ removeChild(loader);
var newSWFRequest:URLRequest = new URLRequest("Steps/" + event.target.name + ".swf");   
loader.load(newSWFRequest); loader.x = Xpos; loader.y = Ypos; //addChild(loader);

loader.contentLoaderInfo.addEventListener(Event.COMPLETE, function(){ 
loader.content.height = 140;
loader.content.scaleX = loader.content.scaleY;});
addChild(loader);

}

//button listeners
NewBusinessPermit.addEventListener(MouseEvent.CLICK, btnCLICK);
RenewBusinessPermit.addEventListener(MouseEvent.CLICK, btnCLICK);
RPTAPayment.addEventListener(MouseEvent.CLICK, btnCLICK);

And i put this script to all the other scenes (1,2,3) to unload the movies fron scene4 然后我将此脚本放到其他所有场景(1、2、3)中,以从场景4中卸载电影

if(stage.contains(loader)){
removeChild(loader);
}
else{
loader = null;  // 've also tried replacing this with gotoAndPlay ("frame name");
}

**i actually wanted to state here that IT in these Scene (1,2 0r 3) there's still a trace of the external child swf that is still loading, remove it from the stage and continue to play whatever tween animations in this current scene. **我实际上想在此声明在这些场景中的IT(1,2 0r 3),仍然有外部子SWF的痕迹,该子SWF仍在加载,将其从舞台中移除并继续播放当前场景中的补间动画。 Else if you trace it that there's none, just continue and play tween animations in this current scene. 否则,如果您没有发现任何痕迹,则继续并在当前场景中播放补间动画。

Well unfortunately i got errors, i dunno if my script meet the objective. 好吧,不幸的是我遇到了错误,如果我的脚本达到了目标,我不知道。 HELP? 救命?

you can try to unload your loaded swf : 您可以尝试卸载已加载的swf:

loader.unloadAndStop( true ); 
if( stage.contains(loader) )    removeChild( loader );
loader = null;

you can see the doc here . 您可以在此处查看文档。

or you can try to stop all clips inside your loader too : 或者您也可以尝试停止加载程序中的所有剪辑:

MovieClip(loader.content).stopAllMovieClips();
if( stage.contains(loader) )    removeChild( loader );
loader = null;

you can see the doc here 你可以在这里看到文档

i think the first method should be good. 我认为第一种方法应该很好。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM