2013-02-21 68 views
0

所以我有一個主SWF作爲啓動其他SWF的主菜單,它啓動罰款,但當其他應用程序運行時,你仍然可以點擊主菜單上的按鈕...AS3 - 嵌套的SWF按鈕問題

function startLoad(e:MouseEvent){ 
    var mLoader:Loader = new Loader(); 
    var mRequest:URLRequest; 

    if (e.target == btnOne){ 
     mRequest = new URLRequest("appOne.swf"); 
    } 
    else if (e.target == btnTwo){ 
     mRequest = new URLRequest("appTwo.swf"); 
    } 

    mLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, onCompleteHandler); 
    mLoader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, onProgressHandler); 
    mLoader.load(mRequest); 
} 

我可以禁用主菜單按鈕,但工作到目前爲止,我還沒有找到一種方法來觸發主菜單重新啓用它們。

+0

你想什麼時候重新啓用它們? – abnvp 2013-02-22 07:16:19

回答

1

當事件到達startLoad方法時,禁用從e.target獲取的按鈕可以改善代碼的行爲。然後區分每個swf的onCompleteHandler方法將使您有機會啓用相應的按鈕。因爲我對你的按鈕類一竅不通,所以我把它稱爲YourButtonClass,我會寫disable();和enable();在下面的示例中用於禁用和啓用按鈕的方法。請用適當的正確類名稱方法或屬性設置替換它們。同時檢查e.target類和按鈕將避免不必要的悲劇。

function startLoad(e:MouseEvent){ 
var mLoader:Loader;  // we havent seen the river, lets not inflate our boat. 
var mRequest:URLRequest; 

if(!(e.target is YourButtonClass)) return;   // no nightmares.. 
if((e.target != btnOne)&&(e.target != btnTwo))return; // no nightmares.. 
YourButtonClass(e.target).disable();     // disable the button here 
mLoader = new Loader(); // river! inflate the boat :) 
if (e.target == btnOne){ 
    mRequest = new URLRequest("appOne.swf"); 
    mLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, onCompleteAppOne); 
} 
else { // we are sure it is btnTwo if not btnOne now... 
    mRequest = new URLRequest("appTwo.swf"); 
    mLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, onCompleteAppTwo); 
}  
mLoader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, onProgressHandler); 
mLoader.load(mRequest); 
} 

// this method is for enabling btnOne 
protected function onCompleteAppOne(Event: e){ 
    btnOne.enable(); 
    commonCompleteOperations(e);// if you have other operations post processing 
} 

// this method is for enabling btnTwo 
protected function onCompleteAppTwo(Event: e){ 
    btnTwo.enable(); 
    commonCompleteOperations(e);// if you have other operations post processing 
} 

// this method is for on complete common operations if you have. 
protected function commonCompleteOperations(Event e){ 
    // do some processing here, for instance remove event listener check for 
    // application domain etc... 
} 

爲了預防,我會聽安全錯誤和IO錯誤事件。這兩個錯誤事件都可以通過每個按鈕/文件的單個處理程序方法來處理。

+0

另外,如果您想禁用並啓用* both *按鈕,則可以在startLoad函數中禁用它們,並且可以實現一個使它們都返回的單個onComplete偵聽器。 – Ihsan 2013-02-27 10:03:23