备忘 target:IEventDispatcher (default = null)

EventDispatcher

()构造函数

public function EventDispatcher(target:IEventDispatcher = null)

语言版本: ActionScript 3.0
运行时版本: AIR 1.0, Flash Player 9, Flash Lite 4

聚合 EventDispatcher 类的实例。

EventDispatcher 类通常用作基类,这意味着大多数开发人员都无需使用此构造函数。但是,实现 IEventDispatcher 接口的高级开发人员则需要使用此构造函数。如果您无法扩展 EventDispatcher 类并且必须实现 IEventDispatcher 接口,请使用此构造函数来聚合 EventDispatcher 类的实例。

参数
 target:IEventDispatcher (default = null) — 调度到 EventDispatcher 对象的事件的目标对象。当 EventDispatcher 实例由实现 IEventDispatcher 的类聚合时,使用此参数;此参数是必需的,以便包含对象可以是事件的目标。请勿在类扩展了 EventDispatcher 的简单情况下使用此参数

 

 

 

 

target:IEventDispatcher (default = null) — 调度到 EventDispatcher 对象的事件的目标对象。当 EventDispatcher 实例由实现 IEventDispatcher 的类聚合时,使用此参数;此参数是必需的,以便包含对象可以是事件的目标。请勿在类扩展了 EventDispatcher 的简单情况下使用此参数。 (AS3帮助)

        一直以来都忽略了构造子的这个参数,实现 IEventDispatcher 接口的时候,target 总是指向实例,而不是包含该实例的类,结果只能一次又一次的直接继承 EventDispatcher 。以下举例备忘。

 

package 
{
 import flash.events.IEventDispatcher;
 import flash.events.EventDispatcher;
 import flash.events.Event;

 class DecoratedDispatcher implements IEventDispatcher
 {
  private var __dispatcher:EventDispatcher;

  public function DecoratedDispatcher()
  {
   __dispatcher = new EventDispatcher(this);
  }
  
  public function addEventListener(type:String, listener:Function, useCapture:Boolean = false, priority:int = 0, useWeakReference:Boolean = false):void
  {
   __dispatcher.addEventListener(type, listener, useCapture, priority);
  }

  public function dispatchEvent(evt:Event):Boolean
  {
   return __dispatcher.dispatchEvent(evt);
  }

  public function hasEventListener(type:String):Boolean
  {
   return __dispatcher.hasEventListener(type);
  }

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

  public function willTrigger(type:String):Boolean
  {
   return __dispatcher.willTrigger(type);
  }
 }
}


 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值