2 Replies Latest reply on Jan 27, 2011 11:15 AM by andrey.mironov

    Get event object from SequenceWaiter

    andrey.mironov

      When I add SequenceWaiter step into the SequenceRunner, how can I get  event object wich was passed into the event? There is the code from my  test function:

       

      var sequence: SequenceRunner = new SequenceRunner(this);
      sequence
      .addStep(new SequenceCaller(manager, function(): void {
          manager
      .startUpload();
      }));
      sequence
      .addStep(new SequenceWaiter(manager, PackageUploadEvent.BEFORE_PACKAGE_UPLOAD, 1000));
      sequence
      .addStep(new SequenceCaller(manager, function(): void {
         
      // TODO: Get event object from PackageUploadEvent.BEFORE_PACKAGE_UPLOAD event
      }));
        • 1. Re: Get event object from SequenceWaiter
          mlabriola Level 4

          Andrey,

           

          The SequenceWaiter doesn't have that functionality by default, its goal is just to wait for an event.

           

          However, the various steps in the Sequence are just instances that implement an interface. So, here is my advice, create a new class, something like SequenceEventWaiter (or whatever makes sense) and extend SequenceWaiter.

           

          This is a simplest-thing-that-could-possibly-work scenario... could be more elegant, but..

           

          To your extension add:

           

          public var event:Event;

           

          override public function setupListeners( testCase:*, sequence:SequenceRunner ):void {

               target.addEventListener( eventName, handleEvent, false, 500 );

               super.setupListeners( testCase, sequence );

          }

           

          private function handleEvent( event:Event ):void {

               this.event = event;

          }

           

          If you do this, (and use your new SequenceEventWaiter instead of the original SequenceWaiter) then you will have the event already nicely stored on this instance before the next step executes.

           

          var sequence: SequenceRunner = new SequenceRunner(this);
          sequence
          .addStep(new SequenceCaller(manager, function(): void {
              manager
          .startUpload();
          }));
          var waiter:MySpecialWaiter =   new MySpecialSequenceWaiter(manager, PackageUploadEvent.BEFORE_PACKAGE_UPLOAD, 1000)

          sequence.addStep( waiter );
          sequence.addStep(new SequenceCaller(manager, function(): void {
              //do something with waiter.event
             
          // TODO: Get event object from PackageUploadEvent.BEFORE_PACKAGE_UPLOAD event
          }));

          HTH,

          Mike

          • 2. Re: Get event object from SequenceWaiter
            andrey.mironov Level 1

            Thanks Michael

             

            Creating new SequenceEventWaiter class is a great idea. I will try it.