7 Replies Latest reply on Nov 24, 2010 9:30 PM by BhaskerChari

    Repeater and dynamic events

    Zolotoj Level 3

      I am using a Panel as my Repeater class. In this Panel I a using a class that raises some dynamic events. In the Panel I have listeners to these events.

      I see that the class does dispatch the event, but the Panel does not get it. What can be wrong?

       

      this is a class code:

      var dynEvent:DynamicEvent= new DynamicEvent("onConnect", true);

      dispatchEvent(dynEvent);

       

      and this is the Panel's

      addEventListener("onConnect", onConnect);

       

      private function onConnect(event:DynamicEvent):void

      {

           trace("nothing is here");

      }

       

      Thanks

        • 1. Re: Repeater and dynamic events
          BhaskerChari Level 4

          Hi Zolotoj,

           

          Have you registered your addEventListener before your class dispatches that event.

           

          Can ypu post your code a little bit more of your Repeater class and the class which is dispatching the event.

           

          Thanks,

          Bhasker Chari.S

          • 2. Re: Repeater and dynamic events
            fleRavix Level 2

            Hi,

            You need to use <metadata> tag in the panel. I mean u shud register the event first

            • 3. Re: Repeater and dynamic events
              Zolotoj Level 3
              // Repeater private var socket:modulecode.Socket = new modulecode.Socket(); public function set data(sewingMachineData:XML):void {      addEventListener("onData", onData);      addEventListener("onSecurityError", onSecurityError);      addEventListener("onClose", onClose);      addEventListener("onError", onError);      addEventListener("onConnect", onConnect);      socket.reConnectSocket(); } private function onConnect(event:DynamicEvent):void {      // it's not getting here      green.visible = true;      red.visible = false; }

               

              // Socket class

               

              public function reConnectSocket():void

              {

                   removeEventListener(ProgressEvent.SOCKET_DATA, onData);

                   // remoteAddress and remotePort are set in the calling process

                   connect(remoteAddress, remotePort);

              }

               

              public function onConnect(event:Event):void

              {

                   flush();

                   addEventListener(ProgressEvent.SOCKET_DATA, onData);

                   // raise event

                   var dynEvent:DynamicEvent = new DynamicEvent("onConnect", true);

                   dispatchEvent(dynEvent);

              }

              • 4. Re: Repeater and dynamic events
                Zolotoj Level 3

                Did not post it properly.

                // Repeater

                private var socket:modulecode.Socket = new modulecode.Socket();

                public function set data(sewingMachineData:XML):void

                {

                     addEventListener("onData", onData);

                     addEventListener("onSecurityError", onSecurityError);

                     addEventListener("onClose", onClose);

                     addEventListener("onError", onError);

                     addEventListener("onConnect", onConnect);

                     socket.reConnectSocket();

                }

                private function onConnect(event:DynamicEvent):void

                {

                     // it's not getting here

                     green.visible = true;

                     red.visible = false;

                }

                // Socket class

                 

                public function reConnectSocket():void

                {

                     removeEventListener(ProgressEvent.SOCKET_DATA, onData);

                     // remoteAddress and remotePort are set in the calling process

                     connect(remoteAddress, remotePort);

                }

                 

                public function onConnect(event:Event):void

                {

                     flush();

                     addEventListener(ProgressEvent.SOCKET_DATA, onData);

                     // raise event

                     var dynEvent:DynamicEvent = new DynamicEvent("onConnect", true);

                     dispatchEvent(dynEvent);

                }

                • 5. Re: Repeater and dynamic events
                  BhaskerChari Level 4

                  Hi Zolotoj,

                   

                  Try to register the eventListener with the Socket class reference...in your Repeater comp.

                   

                  So use socket.addEventListener("onConnect", onConnect);

                  If your other events are also dispatched in the Socket class the register all the eventListeners w.r.t socket class instace as I did above..

                   

                  // Repeater

                  private var socket:modulecode.Socket = new modulecode.Socket();

                  public function set data(sewingMachineData:XML):void

                  {

                       addEventListener("onData", onData);

                       addEventListener("onSecurityError", onSecurityError);

                       addEventListener("onClose", onClose);

                       addEventListener("onError", onError);

                       socket.addEventListener("onConnect", onConnect);

                       socket.reConnectSocket();

                  }

                  private function onConnect(event:DynamicEvent):void

                  {

                       // it's not getting here

                       green.visible = true;

                       red.visible = false;

                  }

                   

                  Thanks,

                  Bhasker

                  • 6. Re: Repeater and dynamic events
                    Zolotoj Level 3

                    Yes, that's what I figured too. But can't I register the listener with the main container, why with class's reference?

                     

                    Thanks

                    • 7. Re: Repeater and dynamic events
                      BhaskerChari Level 4

                      Hi Zolotoj,

                       

                      You can't listen for the event if you register the eventListener with the main container in this case because the socket class in not an UIComponent and is not part of the application display list(which means it is not added to stage) which when dispatches an event the event Object doesn't flow from root Application container down to the target and then again back to the Root Application container in bubbling phase.

                       

                      Always remember Flash Player dispatches the event directly on the target when your Component is a NonVisual component like the Socket class in your case so you need to register listner on the class reference itself.Here the event is dispatched directly by the Socket class which is a non visual component and you also need to register an eventListener on the Socket class instance itself.

                       

                      Also worth noting is that bubbling only works on UI elements. Hope this make you understand...if you still have any doubts please feel free to ask...

                       

                      Thanks,

                      Bhasker

                      1 person found this helpful