2013-09-25 72 views
0

我有兩個名爲'main'和'TimerCountDown'的類。我試圖從'main'類中的'TimerCountDown'調用一個'reset'函數。來自另一個類的調用方法動作腳本3

這是我TimerCountDown類:

public class TimerCountDown extends MovieClip 
    { 
     public function TimerCountDown(t:TextField, timeType:String, timeValue:Number, es:String, _documentclass):void 
     { 
      this.documentclass = _documentclass; 
      this.tfTimeDisplay = t; 
      if (timeType == "seconds") 
      { 
       this.timeInSeconds = timeValue; 
      } 
      if (timeType == "minutes") 
      { 
       this.timeInSeconds = timeValue * 60; 
      } 
      this.tfEndDisplayString = es; 
      this.startTimer(); 
     } 
      public function reset():void{ 
      clockCounter.reset(); 
     } 
} 

如何創建主類的引用使用復位功能在主類的功能是什麼?我只能這樣做

var myTimerObject:TimerCountDown = new TimerCountDown(timer, "seconds", 40, "0!", this); 

但不知道調用復位功能。

回答

0

你可以這樣調用:

myTimerObject.reset(); 
0

您可以在保持主類myTimerObject的參考

public class Main { 


    private var _targetTimerObject:TimerCountDown; 

    public function set targetTimerObject(value:TimerCountDown):void { 

     _targetTimerObject = value; 
    } 

    public function someFunction():void { 

     if (_targetTimerObject) { 
      _targetTimerObject.reset(); 
     } 
    } 

}