5 Replies Latest reply on Jul 1, 2010 1:39 AM by Francisc

    Catching an Event

    Francisc Level 3

      Hello!

       

      In the main application I am dispatching a custom event:

       

      var e:Event=new Event("loggedinUserDataLoaded",true);

      dispatchEvent(e);

       

      In the itemRenderer component of another component hosted inside the parentApplication I am trying to catch it:

       

      addEventListener("loggedinUserDataLoaded",confirmCatch);

       

       

      However, this isn't working.

       

      What am I doing wrong please?

        • 1. Re: Catching an Event
          houseofadobe

          Apparently not on the display list path of the event.

          • 2. Re: Catching an Event
            saisri2k2 Level 4

            You have to create a custom event which is a nw class and extends Event and has a constructor. You can dispatch this custom event in this way.

            • 3. Re: Catching an Event
              houseofadobe Level 1

              Looks like you are not using a FlexEvent but a flash event.   Use FlexEvent instead and it will bubble thru the display list.

              • 4. Re: Catching an Event
                David_F57 Level 5

                hi,

                 

                This might help a bit.......

                 

                ok - main app

                 

                <?xml version="1.0" encoding="utf-8"?>

                <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"

                   xmlns:s="library://ns.adobe.com/flex/spark"

                   xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600" xmlns:ns1="*">

                 

                <fx:Metadata>

                [Event("TransferReady", type="flash.events.Event")]

                </fx:Metadata>

                <fx:Declarations>

                <!-- Place non-visual elements (e.g., services, value objects) here -->

                </fx:Declarations>

                <s:Button x="133" y="127" label="Button" click="dispatchEvent(new Event('TransferReady'));"/>

                <ns1:TestComponent x="556" y="162">

                </ns1:TestComponent>

                </s:Application>

                custom component.
                <?xml version="1.0" encoding="utf-8"?>
                <s:Group xmlns:fx="http://ns.adobe.com/mxml/2009"
                xmlns:s="library://ns.adobe.com/flex/spark"
                xmlns:mx="library://ns.adobe.com/flex/mx" width="400" height="300" creationComplete="group1_creationCompleteHandler(event)">
                <fx:Script>
                <![CDATA[
                import mx.core.FlexGlobals;
                import mx.events.FlexEvent;
                protected function group1_creationCompleteHandler(event:FlexEvent):void
                {
                FlexGlobals.topLevelApplication.addEventListener("TransferReady",onTransferReady);
                }
                private function onTransferReady(event:Event):void
                {
                ta.text="hello world";
                }
                ]]>
                </fx:Script>
                <s:TextArea id="ta" top="0" left="0" bottom="0" right="0"/>
                </s:Group>

                • 5. Re: Catching an Event
                  Francisc Level 3

                  Thanks guys.