3 Replies Latest reply on Dec 15, 2008 7:38 AM by Newsgroup_User

    Custom event

    Bilbo1984
      Hi

      i've a problem..anibody can help me?

      i created this class:

      public class CompleteEvent extends Event
      {
      private var array:ArrayCollection

      public function CompleteEvent(type:String, array:ArrayCollection)
      {
      super(type);
      this.array = array;
      }

      public override function clone():Event {
      return new CompleteEvent(type, array);
      }
      }

      the main class create the array through a socket connection within the socket listeners for Socket.DATA...the socketdata method listeners dispatch the event...

      [Event(name="newEvent", type="CompleteEvent")]
      public class MainApp{
      ....
      socket.addEventListeners(ProgressEvent.SOCKET_DATA, socketData);
      ...
      private function socketData(event:Event):void {

      ...some code to create array from server data...
      //dispatch event
      var dipsatcher:EventDispatcher = new EventDispatcher();
      var ev:CompleteEvent = new CompleteEvent("newEvent", array);
      dispatcher.dispatchEvent(ev);
      }
      }

      and this other class listens for the event

      public class BasePanel extends Panel
      {

      private function dataEventHandler():void {
      trace("Array retrieved");
      }

      public function BasePanel()
      {
      super();
      this.addEventListener("newEvent", dataEventHandler);
      }
      }

      but not working...the BasePanel class doesn't listen for the event..

      thanks a lot

      Regards
      Lorenzo
        • 1. Re: Custom event
          Level 7

          "Bilbo1984" <webforumsuser@macromedia.com> wrote in message
          news:gi5hjd$e5r$1@forums.macromedia.com...
          > Hi
          >
          > i've a problem..anibody can help me?
          >
          > i created this class:
          >
          > public class CompleteEvent extends Event
          > {
          > private var array:ArrayCollection
          >
          > public function CompleteEvent(type:String, array:ArrayCollection)
          > {
          > super(type);
          > this.array = array;
          > }
          >
          > public override function clone():Event {
          > return new CompleteEvent(type, array);
          > }
          > }
          >
          > the main class create the array through a socket connection within the
          > socket
          > listeners for Socket.DATA...the socketdata method listeners dispatch the
          > event...
          >
          > [Event(name="newEvent", type="CompleteEvent")]
          > public class MainApp{
          > ....
          > socket.addEventListeners(ProgressEvent.SOCKET_DATA, socketData);
          > ...
          > private function socketData(event:Event):void {
          >
          > ...some code to create array from server data...
          > //dispatch event
          > var dipsatcher:EventDispatcher = new EventDispatcher();
          > var ev:CompleteEvent = new CompleteEvent("newEvent", array);
          > dispatcher.dispatchEvent(ev);
          > }
          > }
          >
          > and this other class listens for the event
          >
          > public class BasePanel extends Panel
          > {
          >
          > private function dataEventHandler():void {
          > trace("Array retrieved");
          > }
          >
          > public function BasePanel()
          > {
          > super();
          > this.addEventListener("newEvent", dataEventHandler);
          > }
          > }


          "this" isn't what's dispatching the event. Instead, you have an
          eventDispatcher that you create within the scope of a function (so you can't
          add a listener on it) dispatching the event. You have taken away the parts
          of the code that make an event bubble, and I suspect your class isn't on the
          display list anyway.

          HTH;

          Amy


          • 2. Re: Custom event
            Bilbo1984 Level 1
            Hi Amy,

            can you explain me what is the error...i don't undestand what do you mean?

            can you post me a little sample..

            thanks a lot

            Regards Lorenzo
            • 3. Re: Custom event
              Level 7

              "Bilbo1984" <webforumsuser@macromedia.com> wrote in message
              news:gi5srr$rhq$1@forums.macromedia.com...
              > Hi Amy,
              >
              > can you explain me what is the error...i don't undestand what do you mean?
              >
              > can you post me a little sample..
              >
              > thanks a lot
              >
              > Regards Lorenzo

              You may find this helpful:

              http://flexdiary.blogspot.com/2008/11/implementing-ieventdispatcher.html

              Then listen to the instance of the class that implements IEventDispatcher,
              _not_ the class that's doing the listening.