2013-09-25 36 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(); 
     } 
    } 

}