Flex 이벤트 배포(FlexViewer 이벤트 메커니즘) 분리 프로세스
4359 단어 이벤트 배포FlexViewer
AppEvent.as
package com
{
import flash.events.Event;
/**
* @author SamSung
* :2014-7-24 1:21:05
*
*/
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;
}
/**
* The data will be passed via the event. It allows the event dispatcher to publish
* data to event listener(s).
*/
public function get data():Object
{
return _data;
}
/**
* @private
*/
public function set data(value:Object):void
{
_data = value;
}
/**
* The callback function associated with this event.
*/
public function get callback():Function
{
return _callback;
}
/**
* @private
*/
public function set callback(value:Function):void
{
_callback = value;
}
/**
* Override clone
*/
public override function clone():Event
{
return new AppEvent(this.type, this.data, this.callback);
}
/**
* Dispatch this event.
*/
public function dispatch():Boolean
{
return EventBus.instance.dispatchEvent(this);
}
/**
* Dispatch an AppEvent for specified type and with optional data and callback reference.
*/
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);
}
}
}
EventBus.as
package com
{
import flash.events.Event;
import flash.events.EventDispatcher;
/**
* The EventBus allows centrallized communication among modules without
* point-to-point messaging. It uses the singleton design pattern
* to make sure one event bus is available globally. The bus itself
* is only available to the container. Modules use the container's
* static method to communicate with the event bus.
*/
public class EventBus extends EventDispatcher
{
/** Application event bus instance */
public static const instance:EventBus = new EventBus();
/**
* Normally the EventBus is not instantiated via the <b>new</b> method directly.
* The constructor helps enforce only one EvenBus availiable for the application
* (singeton) so that it asures the communication only via a sigle event bus.
*/
public function EventBus()
{
}
/**
* The factory method is used to create a instance of the EventBus. It returns
* the only instanace of EventBus and makes sure no another instance is created.
*/
[Deprecated(replacement="instance")]
public static function getInstance():EventBus
{
return instance;
}
/**
* Basic dispatch function, dispatches simple named events. In the case
* that the event is only significant by the event token (type string),
* this new dispatch method simplify the code.
*/
[Deprecated(replacement="AppEvent.dispatch")]
public function dispatch(type:String):Boolean
{
return dispatchEvent(new Event(type));
}
}
}
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
Android 터치 이벤트 배포 메커니즘 요약boolean Activity.dispatchTouchEvent(MotionEvent ev) boolean ViewGroup.dispatchTouchEvent(MotionEvent ev) PS. View Group의...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.