0
所以我想卸載我的第一個SWF之前加載第二個SWF 當我加載SWF的時候我的問題是第二個SWF是第一個SWF的堆棧 當我從第二個SWF回到第一個聲音播放時也會堆疊 和第一SWF動畫仍然可以看到第二個SWFFlash ActionScript 3.0卸載SWF
1St.SWF代碼:
var pausePoint:Number = 0.00;
var aPlaying:Boolean;
var soundChannel:SoundChannel = new SoundChannel();
var sound:Sound = new Sound(new URLRequest("home.mp3"));
soundChannel = sound.play(0,999);
aPlaying = true;
var loader:Loader = new Loader();
addChild(loader);
btnInfo.addEventListener (MouseEvent.CLICK, loadInfo);
function loadInfo(event : MouseEvent): void{
removeChild(loader);
loader.unloadAndStop();
var SWFRequestInfo:URLRequest = new URLRequest("2nd.swf");
loader.load(SWFRequestInfo);
addChild(loader);
}
2nd.SWF代碼:
var loader:Loader = new Loader();
addChild(loader);
btnBack.addEventListener (MouseEvent.CLICK, loadBack);
function loadBack(event : MouseEvent): void{
removeChild(loader);
loader.unloadAndStop();
var SWFRequestBack:URLRequest = new URLRequest("1st.swf");
loader.load(SWFRequestBack);
addChild(loader);
}
它有沒有解決這個問題的解決方案?
更新2
//main.swf
const FIRST:int = 1;
const SECOND:int = 2;
var current:int;
var loader1:Loader = new Loader();
var loader2:Loader = new Loader();
addChild(loader1);
addChild(loader2);
addEventListener(LoadEvent.LOAD_SWF, loadSWF);
trace("first Load");
loader2.visible=false;
loader1.visible=false;
loader1.load(new URLRequest("1.swf"));
loader1.visible=true;
current=FIRST;
function loadSWF(event:LoadEvent):void
{
if(current == FIRST){
current=SECOND;
loader2.load(new URLRequest(event.url));
loader2.visible=true;
trace("loader2 Loaded");
loader1.unloadAndStop(true);
loader1.visible=false;
trace("loader1 Unloaded");
}
else{
current=FIRST;
loader1.load(new URLRequest(event.url));
loader1.visible=true;
trace("loader1 Loaded");
loader2.unloadAndStop(true);
loader2.visible=false;
trace("loader2 Unloaded");
}
}
1.swf
function clickNext(event:MouseEvent):void{
trace("next clicked");
dispatchEvent(new LoadEvent(LoadEvent.LOAD_SWF, "2.swf"));
}
2.swf
function clickPrev(event:MouseEvent):void{
trace("prev clicked");
dispatchEvent(new LoadEvent(LoadEvent.LOAD_SWF, "1.swf"));
}
LoadEvent.as
package {
import flash.events.Event;
public class LoadEvent extends Event {
public static const LOAD_SWF:String = "LoadSWF";
public var url:String;
public function LoadEvent(type:String, url:String,bubbles:Boolean=true, cancelable:Boolean=false) {
super(type,bubbles,cancelable);
this.url=url;
}
public override function clone():Event
{
return new LoadEvent(type,url,bubbles,cancelable);
}
}
}
你可以給我的事件監聽一些簡單的代碼來卸載當前SWF? – GandhyOnly 2015-04-06 09:27:36
是的。查看更新。 – subdan 2015-04-06 09:33:10
對於遲到的回覆感到抱歉,我仍然不知道如何通過單擊子SWF上的按鈕來運行子SWF時如何運行主函數? – GandhyOnly 2015-05-22 11:31:40