3 Replies Latest reply on Mar 23, 2011 4:19 AM by Shilpi Srivastava

    Identifying custom event

    anandbk Level 1

      Hi Guys,

       

      I am dispatching two custom events from two different .AS file. Let us say events E1 & E2 (each one dispatched from separate .AS file.)

       

      Now i want identify the particular event in IF condtion and do some stuffs.

      I have function like:

       

      public function execute(event:CairngormEvent):void {

       

      // Here  i have 2 IF condtions which will do its stuffs based on particular event.

       

           if ( E1 )

           {

                //do some thing

           }

       

       

            if ( E2 )

           {

                //do some thing

           }

       

       

      }

       

       

      Here, how do i identify/check  the type of event dispatched using CairngormEvent object.

       

      Can anyone help me in this regard with sample code.

       

      Thanks,

      Aaand.

        • 1. Re: Identifying custom event
          _spoboyle Level 4

          are E1 and E2 instances of the same class? do E1 and E2 have teh same event type?

          • 2. Re: Identifying custom event
            Abhinav Sharma Level 2

            You can check the Class of the Event Object.

             

            Inside flash.utils package there is a method  - getQualifiedClassName(object). This will return the name of class from which Object is intantiated. In your case object would be E1 and E2. Now you can match this class in IF STATEMENT.

             

            Thanks.

             

            -

            Abhinav

            • 3. Re: Identifying custom event
              Shilpi Srivastava


              As the these are custom events, so u can give any name to the event.The type of the dispatched event will be identified and listened by the

              appropriate command.


              public class Controller extends FrontController
              {
                     public function Controller()
                     {
                      addCommand(Controller.EVENT_E1,LoginCommand);
                      addCommand(Controller.EVENT_E2,ProductCommand);  
                     }    
                      public static const EVENT_E1:String="e1";
                      public static const EVENT_E2:String="e2";
              }

               

              public class Command extends SequenceCommand implements ICommand
              {

              public override function execute(event:CairngormEvent):void
              {
                   switch( event )

                   {
                    case E1:
                    //typecaste the events and use
                         E1(event).

                             //do some thing

                    case E2:
                    //typecaste the events and use
                         E2(event).

                             //do some thing

                   }

              }// end of execute

               

              }//command