Flex 事件分發(fā)(FlexViewer事件機(jī)制)剝離過程
更新時(shí)間:2014年07月27日 09:54:46 投稿:whsnow
本節(jié)主要介紹了如何將FlexViewer里面的事件分發(fā)及監(jiān)聽事件機(jī)制剝離出來在其他項(xiàng)目中使用,需要的朋友可以參考下
將FlexViewer里面的事件分發(fā)及監(jiān)聽事件機(jī)制剝離出來在其他項(xiàng)目中使用
AppEvent.as
package com
{
import flash.events.Event;
/**
* @author SamSung
* 創(chuàng)建時(shí)間: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));
}
}
}
相關(guān)文章
js調(diào)用Flex中的方法并向flex中傳參及flex調(diào)用js示例
本文為大家詳細(xì)介紹喜愛js調(diào)用Flex中的方法以及向flex中傳參與flex調(diào)用js,具體示例如下,感興趣的朋友不妨參考下,希望對(duì)大家有所幫助2013-07-07
Flex 錯(cuò)誤(mx.messaging.messages::RemotingMessage)分析
有時(shí)我們?cè)谧鲰?xiàng)目的時(shí)候會(huì)遇到Flex 錯(cuò)誤提示mx.messaging.messages::RemotingMessage,那么產(chǎn)生這個(gè)錯(cuò)誤的原因是什么呢,今天我們來分析下2014-06-06
Flex tree加虛線顯示效果并且替代原始圖標(biāo)
Flex tree修改默認(rèn)圖標(biāo)并且加虛線顯示效果,實(shí)在是看不下去那種巨丑無比的小箭頭+文件夾的顯示方式,具體實(shí)現(xiàn)如下,有此需求的朋友可以參考下,希望對(duì)家有所幫助2013-08-08
flex 遍歷Object對(duì)象內(nèi)容的實(shí)現(xiàn)代碼
這篇文章主要介紹了flex 遍歷Object對(duì)象內(nèi)容的實(shí)現(xiàn)代碼,需要的朋友可以參考下2014-07-07
FLEX給頁面添加滾動(dòng)條實(shí)現(xiàn)思路及代碼
給頁面添加滾動(dòng)條的方法有很多,使用js獲取瀏覽器窗口的寬高,根據(jù)瀏覽器窗口寬高修改樣式,讓滾動(dòng)條出現(xiàn),具體的實(shí)現(xiàn)如下,需要的朋友可以參考下2013-11-11
Flex4 使用itemRenderer 為Tree加線具體實(shí)現(xiàn)
本文為大家詳細(xì)介紹下Flex4如何使用itemRenderer 為Tree加線,感興趣的朋友可以參考下2013-12-12

