所以我想在加载第二个SWF之前卸载我的第一个SWF 当我加载SWF时我的问题是第二个SWF是第一个SWF的堆栈 当我从第二个SWF回到第一个声音时,它也会叠加 第一个SWF的动画仍然可以在第二个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);
}
它有解决这个问题的任何解决方案吗?
//的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 );
}
}
}
答案 0 :(得分:1)
制作第3个(主)SWF,它将加载/卸载第1个和第2个SWF。当您点击btnBack
或btnInfo
时,您可以发送一些活动。此事件可以捕获主SWF并卸载当前SWF并加载下一个SWF。
<强>更新强>
这是主要SWF的代码:
const FIRST:int = 1;
const SECOND:int = 2;
var current:int;
var loader:Loader = new Loader();
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, loadedHandler);
addChild(loader);
loadFirst();
function loadedHandler(event:Event):void
{
loader.content.addEventListener(Event.CLOSE, closeHandler);
}
function closeHandler(event:Event):void
{
if (current == FIRST)
{
loadSecond();
}
else if (current == SECOND)
{
loadFirst();
}
}
function loadFirst():void
{
if (loader.content)
{
loader.unloadAndStop(true);
}
current = FIRST;
loader.load(new URLRequest("1st.swf"));
}
function loadSecond():void
{
if (loader.content)
{
loader.unloadAndStop(true);
}
current = SECOND;
loader.load(new URLRequest("2nd.swf"));
}
从MouseEvent.CLICK处理程序中的第一个和第二个SWF调度下一个代码:
dispatchEvent(new Event(Event.CLOSE));
更新#2
const FIRST:int = 1;
const SECOND:int = 2;
var current:int;
var loader1:Loader = new Loader();
var loader2:Loader = new Loader();
loader1.contentLoaderInfo.addEventListener(Event.COMPLETE, loaded1Handler);
loader2.contentLoaderInfo.addEventListener(Event.COMPLETE, loaded2Handler);
addChild(loader1);
addChild(loader2);
loadFirst();
function loaded1Handler(event:Event):void
{
loader1.content.addEventListener(Event.CLOSE, closeHandler);
loader2.visible = false;
}
function loaded2Handler(event:Event):void
{
loader2.content.addEventListener(Event.CLOSE, closeHandler);
loader1.visible = false;
}
function closeHandler(event:Event):void
{
if (current == FIRST)
{
loadSecond();
}
else if (current == SECOND)
{
loadFirst();
}
}
function loadFirst():void
{
if (loader1.content)
{
loader1.unloadAndStop(true);
}
current = FIRST;
loader1.load(new URLRequest("1.swf"));
loader1.visible = true;
}
function loadSecond():void
{
if (loader2.content)
{
loader2.unloadAndStop(true);
}
current = SECOND;
loader2.load(new URLRequest("2.swf"));
loader2.visible = true;
}
更新#3
const FIRST:int = 1;
const SECOND:int = 2;
var current:int;
var loader1:Loader = new Loader();
var loader2:Loader = new Loader();
loader1.contentLoaderInfo.addEventListener(Event.COMPLETE, loader1Compl);
loader2.contentLoaderInfo.addEventListener(Event.COMPLETE, loader2Compl);
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 loader1Compl(event:Event):void
{
loader2.unloadAndStop(true);
loader2.visible=false;
trace("loader2 Unloaded");
}
function loader2Compl(event:Event):void
{
loader1.unloadAndStop(true);
loader1.visible=false;
trace("loader1 Unloaded");
}
function loadSWF(event:LoadEvent):void
{
if(current == FIRST){
current=SECOND;
loader2.load(new URLRequest(event.url));
loader2.visible=true;
trace("loader2 Loaded");
}
else{
current=FIRST;
loader1.load(new URLRequest(event.url));
loader1.visible=true;
trace("loader1 Loaded");
}
}