从另一个类Action Script 3调用方法

时间:2013-09-25 03:08:18

标签: actionscript-3 flash

我有两个名为'main'和'TimerCountDown'的类。我试图从'main'类中的'TimerCountDown'调用单个函数'reset'。

这是我的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();
        }
}

如何在主类中创建引用使用主类函数中的reset函数?我只能做某事......

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

但不知道调用重置功能。<​​/ p>

2 个答案:

答案 0 :(得分:0)

您可以这样称呼它:

myTimerObject.reset();

答案 1 :(得分: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();
       }
   }

}