2011-03-26 105 views

回答

1

只需在最後一幀(或您想要的位置)的舞臺上添加一個按鈕,讓我們說「resetButton_mc」。

resetButton_mc.addEventListener(MouseEvent.CLICK, reset); 

function reset(event:MouseEvent):void 
{ 
    //Reset all variables and send the playhead to the appropriate frame 
}; 

乾杯, 羅布

+0

我想要一個真正的資源等。不是功能! – 2011-03-26 23:59:49

+0

AS中沒有「真正的重置」隊友,抱歉! – robertp 2011-03-27 00:13:07

1

製作一個按鈕實例,說resetBtn

resetBtn.onRelease = function(){ 
    //manually reset each variable 
     userName = ""; 
     userAge = 0; 
     . 
     . 
     . 

     } 

這仍然使用功能雖然。

1

正如其他人所說,Flash Player中沒有真正的重置方法。根據項目的複雜性,將每個屬性和變量設置爲默認值可能無法管理。

如果是這樣,你可能要考慮兩個選項的情況下:

總結你的代碼中有一個附加的「解構」方法的類。解構方法應該關注事件監聽者,而不是什麼。構造函數應該調用像init這樣的方法來設置所有的變量。這樣你就不會把代碼加倍。

例如:

package { 
    import flash.events.Event; 
    import flash.events.EventDispatcher; 

    public class Foo extends EventDispatcher { 

     private var _a:String; 

     public function Foo() { 
      init(); 
     } 

     public function init():void { 
      _a = "Default Value"; 
      addEventListener(Event.ENTER_FRAME, onEnter); 
     } 

     public function deconstruct():void { 
      // Clean up time 
      removeEventListener(Event.ENTER_FRAME, onEnter); 
     } 

     private function onEnter(e:Event):void { 
      trace("frame"); 
     } 

     public function get a():String { return _a; }  
     public function set a(value:String):void { _a = value; } 
    } 
} 

然後在你的主時間軸

var foo:Foo = new Foo(); 

resetButton.addEventListener(MouseEvent.CLICK, onClick); 

function onClick(e:MouseEvent):void { 
    foo.deconstruct(); 
    foo = new Foo(); 
} 

這將確保你是真正的重置

1
btn.addEventListener(MouseEvent.CLICK, onClick); 
function onClick(e:MouseEvent):void 
{ 
    navigateToURL(new URLRequest(stage.LoaderInfo.url), '_level0'); 
} 

這上面的代碼將重新加載您的SWF文件

相關問題