Flex 事件分发(FlexViewer事件机制)剥离过程(flex.)全程干货

随心笔谈1年前 (2023)发布 admin
155 0


package com
{
import flash.events.Event;

public class AppEvent extends Event
{
//————————————————————————–
//
// Properties
//
//————————————————————————–

private var _data:Object;

private var _callback:Function;

public function AppEvent(type:String, data:Object=null, callback:Function=null)
{
super(type);
_data=data;
_callback=callback;
}

public function get data():Object
{
return _data;
}

public function set data(value:Object):void
{
_data=value;
}

public function get callback():Function
{
return _callback;
}

public function set callback(value:Function):void
{
_callback=value;
}

public override function clone():Event
{
return new AppEvent(this.type, this.data, this.callback);
}

public function dispatch():Boolean
{
return EventBus.instance.dispatchEvent(this);
}

public static function dispatch(type:String, data:Object=null, callback:Function=null):Boolean
{
return EventBus.instance.dispatchEvent(new AppEvent(type, data, callback));
}

public static function addListener(type:String, listener:Function, useCapture:Boolean=false, priority:int=0, useWeakReference:Boolean=false):void
{
EventBus.instance.addEventListener(type, listener, useCapture, priority, useWeakReference);
}

public static function removeListener(type:String, listener:Function, useCapture:Boolean=false):void
{
EventBus.instance.removeEventListener(type, listener, useCapture);
}

}
}

© 版权声明

相关文章