控制/初始化外部类[AS3]

问题描述

| 在开除之前,我知道在SO上有很多非常相似的问题。但是,给出的解决方案都没有对我有任何帮助,可能是因为我的情况有所不同。 我有一个加载外部类的主类(单独的.as文件)。在此外部类中,有几个对象绑定了补间和时间事件。 我想做的是在Main类中调用某个函数时开始动画。但是,我已经尝试了多种方法来停止和/或重置外部类中的动画,因此,如果在Main中调用了所需的函数,它将从头开始。 Main.as:
package  {
   //required imports

   public class Main extends MovieClip {
   var myClass:MyClass = new MyClass; //this is the external class
   var button:Button = new Button; //movieclip in the library   

      public function Main() {
         addChild(myClass); //I want to do this here so the objects show from the start
         //try 1: myClass.gotoAndStop(1);
         //try 2: myClass.stop();

         button.addEventListener(MouseEvent.MOUSE_CLICK,playAnimation);
      }

      function playAnimation (e:MouseEvent) {
         //try 1: myClass.gotoAndplay(1);
         //try 2: myClass.start();
         //try 3: controlling the startTweening() function in MyClass,I tried different ways
      }
   }
}
问题从上面的Main类开始。我还不想动画! MyClass.as:
package {
  //required imports

   public class MyClass extends MovieClip {
      //vars

      public function MyClass() {
         startTweening();
      }
      function startTweening() {
        //tween event
        //calling next function (with use of a TimerEvent) after tween is done. This is repeated several times.
      }
   }
 }
此类中的所有内容都可以正常运行,所以这不是问题。 如果有什么不同,我在MyClass中使用TweenMax进行补间。我没有在.fla中使用时间轴。 任何帮助将不胜感激!     

解决方法

        如果不想在创建
MyClass
时设置动画,请从
MyClass
的构造函数中删除
startTweening();
调用。 将
startTweening();
设为
public
函数,并在需要时使用
myClass.startTweening()
对其进行调用。 这是MyClass
public class MyClass extends MovieClip {
  //vars

  public function MyClass() {

  }

  public function startTweening() {
    //tween event
    //calling next function (with use of a TimerEvent) after tween is done. This is repeated several times.
  }
}
这里是主班
public class Main extends MovieClip {
   var myClass:MyClass;
   var button:Button = new Button; //movieclip in the library   

      public function Main() {
         myClass = addChild(new MyClass()) as MyClass; 
         button.addEventListener(MouseEvent.MOUSE_CLICK,playAnimation);
      }

      function playAnimation (e:MouseEvent) {
         myClass.startTweening();
      }
   }