加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

flex 事件 一处分发,任意监听

发布时间:2020-12-15 04:42:24 所属栏目:百科 来源:网络整理
导读:代码: package?com.evrnt ? { ? ????import?flash.events.Event; ? ????import?flash.events.EventDispatcher; ? ????import?flash.events.IEventDispatcher; ? ? ????public?class?InputEventDispatcher???{ ? ???????? ? ????????private?static?var?_ins

代码:

 
 
  1. package?com.evrnt ?
  2. { ?
  3. ????import?flash.events.Event; ?
  4. ????import?flash.events.EventDispatcher; ?
  5. ????import?flash.events.IEventDispatcher; ?
  6. ?
  7. ????public?class?InputEventDispatcher???{ ?
  8. ???????? ?
  9. ????????private?static?var?_inst:InputEventDispatcher; ?
  10. ????????private?var?eventDispatcher:IEventDispatcher; ?
  11. ???????? ?
  12. ????????public?function?InputEventDispatcher(target:IEventDispatcher?=?null){ ?
  13. ????????????eventDispatcher?=?new?EventDispatcher(target); ?
  14. ????????} ?
  15. ???????? ?
  16. ????????/**?获取FastReportEventDispatcher类的唯一实例?*/ ?
  17. ????????public?static?function?getInstance():InputEventDispatcher{ ?
  18. ????????????if(!_inst){ ?
  19. ????????????????_inst?=?new?InputEventDispatcher(); ?
  20. ????????????} ?
  21. ????????????return?_inst; ?
  22. ????????} ?
  23. ???????? ?
  24. ????????/**?添加事件侦听器函数?*/ ?
  25. ????????public?function?addEventListener(type:String,listener:Function,useCapture:Boolean=false,pririty:int=0,useWeakReference:Boolean=true):void{ ?
  26. ????????????eventDispatcher.addEventListener(type,listener,useCapture,pririty,useWeakReference); ?
  27. ????????} ?
  28. ???????? ?
  29. ????????/**?删除事件监听器函数?*/ ?
  30. ????????public?function?removeEventListener(type:String,priority:int=0,useWeakReference:Boolean=true):void{ ?
  31. ????????????eventDispatcher.removeEventListener(type,useCapture); ?
  32. ????????} ?
  33. ???????? ?
  34. ????????/**?事件派发函数?*/ ?
  35. ????????public?function?dispatchEvent(event:InputEvent):Boolean{ ?
  36. ????????????return?eventDispatcher.dispatchEvent(event); ?
  37. ????????} ?
  38. ???????? ?
  39. ????????/**?检查是否已经存在事件侦听器?*/ ?
  40. ????????public?function?hasEventListener(type:String):Boolean{ ?
  41. ????????????return?eventDispatcher.hasEventListener(type); ?
  42. ????????} ?
  43. ???????? ?
  44. ????????/**?检查eventDispatcher?对象或其他任何数组是否注册了指定类型的事件侦听器?*/ ?
  45. ????????public?function?willTrigger(type:String):Boolean{ ?
  46. ????????????return?eventDispatcher.willTrigger(type); ?
  47. ????????} ?
  48. ????} ?
  49. }?

自定义一个类用来发送和监听事件,就可以实现在任意地方监听。

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读