as3 事件Event

事件流

捕获 - 目标 - 冒泡

事件对象

e.target    //事件的派发者

e.currentTarget  //事件处理者

e.cancelable;   e.preventDefault();  //事件能不能取消

e.eventPhase;     //事件在时间流哪个阶段被触发(事件所处阶段)

e.localX   //鼠标点击在按钮中的位置

e.localY   // 鼠标点击在按钮中的位置

e.stageX   //相对于舞台的位置

e.stageY   //相对于舞台的位置

事件对象

package {
    import flash.events.Event;
    public class CustomEvent extends Event{
        
        public static const CUSTOM_EVENT:String = "CUSTOM_EVENT";

        public var data:String;
        public function CustomEvent(type:String, data:String,bubble:Boolean = false, cancelable:Boolean= false){
            super(type,bubble,cancelable);
            this.data = data;
            
        }
        
        override public function clone():Event{
            return new CustomEvent(type, data, bubbles, cancelable);
        }
    }
}


function clickHandler(e:MouseEvent):void
{
    //派发事件
    this.dispatchEvent(new CustomEvent(CustomEvent.CUSTOM_EVENT, "hello,Custom Event!"));
}
addEventListener(CustomEvent.CUSTOM_EVENT, customEventHandler);


function customEventHandler(e:CustomEvent):void
{
    trace(e.data);
}




发布了166 篇原创文章 · 获赞 26 · 访问量 15万+

猜你喜欢

转载自blog.csdn.net/qq_28710983/article/details/105430295