2013-02-09 72 views
2

我正在使用此代碼來加載和卸載外部swf的按鈕。當我點擊按鈕,瑞士法郎加載,當我再次點擊按鈕瑞士法郎卸載,但聲音仍然存在,只是瑞士法郎屏幕消失。完成卸載外部swf和聲音

請更正此代碼,我希望swf完成卸載。

printer.addEventListener(MouseEvent.CLICK, fl_ClickToLoadUnloadSWF); 

var fl_Loader:Loader; 

//This variable keeps track of whether you want to load or unload the SWF 
var fl_ToLoad:Boolean = true; 

function fl_ClickToLoadUnloadSWF(event:MouseEvent):void 
{ 
    if(fl_ToLoad) 
    { 
     fl_Loader = new Loader(); 
     addChild(fl_Loader); 
     fl_Loader.load(new URLRequest("quiz.swf")); 


printer.x=100; 
printer.y=100; 
    } 
    else 

    {  fl_Loader.unloadAndStop(); 

     removeChild(fl_Loader); 
     fl_Loader = null; 

printer.x=155; 
printer.y=334; 
    } 
    // Toggle whether you want to load or unload the SWF 
    fl_ToLoad = !fl_ToLoad; 
} 
+0

嘗試在卸載它之前調用fl_Loader.haltSPP(); – David 2013-02-10 12:23:41

+0

請告訴我必須將此代碼添加到哪一行?因爲我加了'fl_Loader.haltSPP(); fl_Loader.unloadAndStop();'但得到錯誤 – hamidreza 2013-02-10 19:15:26

回答

0

如果您可以訪問加載的swf中的代碼,那麼您可以添加Event.UNLOAD偵聽器。在事件處理程序,你可以做一些清潔:

  • 停止所有的聲音,
  • 停止視頻,
  • 移除事件偵聽器(特別是那些連接到Stage

這樣,卸貨應該平穩而輕鬆。