actionscript 3-是否可以临时删除eventListener(即,直到函数执行完毕)



我现在正在执行actionscript 3,想知道是否可以暂时删除和eventListner。然而,我知道removeEventListener,它完全删除了eventListener,我无法再次单击按钮。

如果你想要更多的细节,这里是确切的问题。我有一个功能,当按下一个按钮时,一个物体就会出现。在生成该对象的函数中,有一个eventListener,它导致一个允许用户按下该对象的功能。当您按下该对象时,它将消失,按钮将设置动画。但是,由于原始eventListener仍然存在,因此可以在运动中按下对象并创建新对象。关键是:我想做的是在按钮移动时禁用eventListener,并在按钮停止时重新激活它。

最好的方法是简单地使用一个标志,该标志告诉函数动画是否完成。以下是我所说的使用TweenLite作为青少年库的示例:

public class CreateButton extends Sprite{
        private var animating:Boolean = false;
        public function CreateButton(){
            this.addEventListener(MouseEvent.CLICK, onClick, false, 0, true);
        }
        private function onClick(event:MouseEvent):void{
            if(this.animating == false){
                // Trigger creation functionality
                TweenLite.to(this, 0.5, {/* Parameters for the actual animation */ onComplete:animationComplete});      
                this.animating = true;
            }
        }
        private function animationComplete():void{
            this.animating = false;
        }
    }

如果要禁用侦听器的功能,最好删除它。但是,如果您想在不删除侦听器的情况下禁用它的单击功能,则可以将.mouseEnabled设置为false。

最新更新