Guest User

Untitled

a guest
Jun 25th, 2018
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /**
  2.          * Listens to an event on the given object and returns a reporter function
  3.          * that returns true if the event has been called.
  4.          *
  5.          * @example
  6.          * <p>
  7.          * The following example creates a simple <code>DropDown</code> instance. The dropdown uses event listeners to capture
  8.          * user interaction.
  9.          * </p>
  10.          * <listing>
  11.              var dispatcher:EventDispatcher = new Sprite();
  12.              var spy:Function = TestUtil.spy(dispatcher, Event.OPEN);
  13.              trace(spy()); // false;
  14.              dispatcher.dispatchEvent(Event.OPEN);
  15.              trace(spy()); // true;
  16.          * </listing>
  17.          */
  18.         public static function spyOnEvent(eventTarget : EventDispatcher, eventType : String) : Function
  19.         {
  20.             var didFire : Boolean = false;
  21.             eventTarget.addEventListener( eventType, function(e : Event) : void
  22.             {
  23.                 if (e.type == eventType)
  24.                 {
  25.                     didFire = true;
  26.                 }
  27.             } );
  28.  
  29.             return function() : Boolean
  30.             {
  31.                 return didFire;
  32.             };
  33.         };
Add Comment
Please, Sign In to add comment