Actionscript 3 AS3如何从时间轴操作类的不同实例

Actionscript 3 AS3如何从时间轴操作类的不同实例,actionscript-3,class,Actionscript 3,Class,我正在尝试使用as3创建菜单,但似乎找不到完成它的方法。 所以我写了一个类,附加到一个movieclip上,我把它的几个实例放在舞台上 package { import flash.events.Event; import flash.events.MouseEvent; import fl.transitions.Tween; import fl.transitions.TweenEvent; import fl.transitions.easing.*; import flash.di

我正在尝试使用as3创建菜单,但似乎找不到完成它的方法。

所以我写了一个类,附加到一个movieclip上,我把它的几个实例放在舞台上

package {

import flash.events.Event;
import flash.events.MouseEvent;
import fl.transitions.Tween;
import fl.transitions.TweenEvent; 
import fl.transitions.easing.*;
import flash.display.*;

public class ServicesButtons extends MovieClip {

    public function ServicesButtons() {

        shapemc.width = 0;

        this.addEventListener(MouseEvent.ROLL_OVER, mouseOn);
        this.addEventListener(MouseEvent.ROLL_OUT, mouseOff);
        this.addEventListener(MouseEvent.CLICK, clicked);

        function mouseOn(e:Event) {
            var shapeGrow:Tween = new Tween(shapemc, "width", Strong.easeOut, 0, 200, .3, true);
        }

        function mouseOff(e:Event) {
            var shapeShrink:Tween = new Tween(shapemc, "width", Strong.easeOut, shapemc.width, 0, .3, true);
        }

        function clicked(e:Event){
            removeEventListener(MouseEvent.ROLL_OUT, mouseOff);     
            removeEventListener(MouseEvent.ROLL_OVER, mouseOn);
        }

    }

}
}

我希望动画在单击某个按钮时不会回滚,我希望动画在单击其他按钮时返回


我的问题是,我如何从这里开始,我在网上搜索线索,根据我的理解,我可以在类中设置变量,并在时间轴上更改它们,并使用事件侦听器捕获更改。我尝试过这样做,但我总是以一些多余的方式结束,而这些方式让我一事无成……

我必须保留以前单击过的按钮:

public class ServicesButtons extends MovieClip {

    private static var activeButton : ServicesButtons;

    public function ServicesButtons() {
        setListener();
        this.addEventListener(MouseEvent.CLICK, clicked);
    }

    private function mouseOn(e:Event) {
        var shapeGrow:Tween = new Tween(shapemc, "width", Strong.easeOut, 0, 200, .3, true);
    }

    private function mouseOff(e:Event) {
        var shapeShrink:Tween = new Tween(shapemc, "width", Strong.easeOut, shapemc.width, 0, .3, true);
    }

    private function clicked(e:Event){
        if(activeButton != this)
        {
            if(activeButton)
                activeButton.setListener();
            setListener();
            activeButton = this;
        }
    }

    public  function setListener() : void{
            if(hasEventListener(MouseEvent.ROLL_OUT))
            {
                removeEventListener(MouseEvent.ROLL_OUT, mouseOff);     
                removeEventListener(MouseEvent.ROLL_OVER, mouseOn);
            }else{

                addEventListener(MouseEvent.ROLL_OVER, mouseOn);
                addEventListener(MouseEvent.ROLL_OUT, mouseOff);
                mouseOff(null);
            }

    }

}