内容简介:本节主要介绍了如何将FlexViewer里面的事件分发及监听事件机制剥离出来在其他项目中使用,需要的朋友可以参考下
将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));
}
}
}
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持 码农网
猜你喜欢:- 详解JS事件 - 事件模型/事件流/事件代理/事件对象/自定义事件
- React 事件和 Dom 事件
- react事件系统之事件触发
- JS 中的自定义事件和模拟事件
- 事件社交网络:深度用户模型的内容事件推荐
- 1.21 JQuery4:鼠标事件与滚动事件
本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。
计算机程序设计艺术(第1卷)
[美] 唐纳德·E. 克努特 / 苏运霖 / 国防工业出版社 / 2002-9 / 98.00元
7卷本《计算机程序设计艺术》的第1卷以基本的程序设计概念和技术开始,然后专注于信息结构——计算机内部信息的表示、数据元素之间的结构关系以及如何有效地处理它们,给出了对于模拟、数值方法、符号计算、软件和系统设计的初等应用。书中附有大量习题和答案,标明了难易程序及数学概念的使用。 此新版本增加了几十项简单且重要的算法和技术,并对有关数学预备知识作了大量修改以适应现时研究的趋势。一起来看看 《计算机程序设计艺术(第1卷)》 这本书的介绍吧!