so I want to unload my 1st SWF before load 2nd SWF my problem when I load SWF is 2nd SWF is stack with 1st SWF and when I back from 2nd SWF to 1ST sound play will Stack too and 1st SWF's animation can still seen on 2nd SWF
1St.SWF Code:
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 Code:
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);
}
its there any solution to solve this problem?
Updated 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 );
}
}
}