7 Replies Latest reply on Jun 9, 2007 2:05 PM by kglad

    AS3 custom event problem

    EZ42
      Hi,
      I've encountered a problem when trying to dispatch a custom event between two brothers in the hirrarchy tree.
      When dispatched from one of the children, the parent can listen to this event, but other children can not.
      Anybody knows why ???

      Thanks,
      EZ42
        • 1. Re: AS3 custom event problem
          kglad Adobe Community Professional & MVP
          because your events are dispatched by instances and siblings are not in the instance hierarachy.

          if you want all the class members to respond to an instance event, store the class members in an array and cycle through them in an event listener function.
          • 2. Re: AS3 custom event problem
            EZ42 Level 1
            Hi,

            Thanks for the quick reply.

            I simply don't get it.
            I have a root class which adds two different children of different classes. One child dispatched an event, and the other is supposed to get it. Both of the are now supposed to be in the instance hirrarchy, or am I wrong?

            Logically, I'd figure this should work smooth and simple without any need for any looping or such.
            Right now, the root class can recieve the event dispatched by child1, but I can't make child2 recieve any event dispatched by either the root or child1.

            I'd appreciate if you could show me the way...
            thanks again,

            EZ42
            • 3. Re: AS3 custom event problem
              kglad Adobe Community Professional & MVP
              by root class do you mean a base class? and by adding children of different classes do you mean you have two subclasses that extend your base class and each of those subclasses have an instance? and these two instances need to dispatch events to the other?
              • 4. AS3 custom event problem
                EZ42 Level 1
                Hi,

                No, I mean that I have 3 different classes, all 3 are subclasses of Sprite and Sprite alone.
                the root class is called Try1
                then there are two classes calles Aobj and Bobj which are both instanciated to the Try1 child-list.
                All I want is for Aobj to dispatch an event and for Bobj to listen to that event.
                In the example I also tried to catch the event on the root class and re-dispatch it, but that doesn't work as well.
                see examples:
                Thanks.

                • 5. Re: AS3 custom event problem
                  kglad Adobe Community Professional & MVP
                  events are not globally transmitted. they are dispatched by specific instances (or classes) and can be detected only by objects in the event flow.
                  • 6. Re: AS3 custom event problem
                    EZ42 Level 1
                    Gotcha.
                    now it works.
                    thanks a lot.
                    • 7. Re: AS3 custom event problem
                      kglad Adobe Community Professional & MVP
                      you're welcome.