Global dispatcher AS3


/ Published in: ActionScript 3
Save to your folder(s)



Copy this code and paste it in your HTML
  1. import flash.events.Event;
  2. import flash.events.EventDispatcher;
  3. import flash.events.IEventDispatcher;
  4.  
  5. public class Dispatcher implements IEventDispatcher {
  6.  
  7. private static var instance : EventDispatcher = new EventDispatcher();
  8.  
  9. public function Dispatcher() {
  10. if (instance) {
  11. throw new Error( "Dispatcher and can only be accessed through Dispatcher.getInstance()" );
  12. }
  13. }
  14.  
  15. public static function getInstance() : EventDispatcher {
  16. return instance;
  17. }
  18.  
  19. /* Miembros de flash.events.IEventDispatcher */
  20.  
  21. public function addEventListener(type:String, listener:Function, useCapture:Boolean = false, priority:int = 0,
  22. useWeakReference:Boolean = false):void{
  23. instance.addEventListener(type, listener, useCapture, priority, useWeakReference);
  24. }
  25.  
  26. public function dispatchEvent(event:Event):Boolean {
  27. return instance.dispatchEvent(event);
  28. }
  29.  
  30. public function hasEventListener(type:String):Boolean {
  31. return instance.hasEventListener(type);
  32. }
  33.  
  34. public function removeEventListener(type:String, listener:Function, useCapture:Boolean = false):void{
  35. instance.removeEventListener(type, listener, useCapture);
  36. }
  37.  
  38. public function willTrigger(type:String):Boolean{
  39. return instance.willTrigger(type);
  40. }
  41. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.