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);
}




 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章