4 Replies Latest reply on Apr 28, 2010 5:57 AM by miguel8312

    listening in main application for event coming from custom component

    miguel8312 Level 3

      I have a custom component that im using for a login.  i watch videos and tutorials on how to pass variables between custom components and application. the problem im having is that must tutorials or explanation have you put the event on the custom component and then it refers to some function within the main app.

      Is there a way to just listen on the main app when that event kicks off? ive been trying for hours and i know there has to be something im missing it cant be that hard. any help i would really appreciate.

      Thanks

      Miguel

        • 1. Re: listening in main application for event coming from custom component
          Ansury Level 3

          Sounds like you're asking about addEventListener():

           

               <fx:Script>
                    <![CDATA[
                         import mx.events.FlexEvent;
                         
                         protected function windowedapplication1_creationCompleteHandler(event:FlexEvent):void
                         {
                              comp.addEventListener("test", testHandler);
                         }
                         
                         private function testHandler(e:Event):void {
                              
                              trace(e);
                         }
                    ]]>
               </fx:Script>
               
               <local:TestComponent id="comp"/>
          

           

           

          Add an event listener on your custom component (first string is the 'type' of the event).

          1 person found this helpful
          • 2. Re: listening in main application for event coming from custom component
            David_F57 Level 5

            hi,

             

            The following example was done as a simple demo of states, but the login component (state1), has a simple custom event that is dispatched by the login ok button, the event could be extended to transfer the login information to the main app as well, in this instance becuase the login 'screen' always exists any public vars or input box fields would be available to the main app anyway.

             

             

            http://gumbo.flashhub.net/wizard/  source included

             

             

            David.

            • 3. Re: listening in main application for event coming from custom component
              -skitch-

              Ansury would be correct.  Flex is nice in that there are so many ways to do things...

               

              Most of the events are given to you pretty nicely in the MXML, so leverage that as much as can.

               

              Dont forget the removeEventListener() when you're done logging in.

              1 person found this helpful
              • 4. Re: listening in main application for event coming from custom component
                miguel8312 Level 3

                Thanks all for your response. I actually know all about the add eventlistener.

                the problem is that i have a custom component that i just call from the main app and center it as the login page. Then when the user logs in. The function for validating the user is on the custom component which i want then to fire off an event if the user is a valid user and pass a variable to the main app. I think you guys have given me enough to go on.

                Thank you guys

                Really appreciated.

                Miguel