2 Replies Latest reply on Mar 5, 2010 6:35 AM by CoreyRLucier

    Anything wrogn with this dispatchEvent?

    Luis Pedro Ferreira Level 1

      Looks like a begginer question bu

      t i really don't know wat am i doing wrong. Used to work a lot with eventDispatchers but now it seams not working.

       

      File 1:

      private function init():void{
           dispatchEvent(new Event("myEvent_eventDispatcher", true, true))
      }

       

      File2:

      private function init():void{
           addEventListener("myEvent_eventDispatcher", myEvent_eventHandler);
      }

       

      private function myEvent_eventHandler(e:Event):void{

           Alert.show("Event dispatched");

      }

       

      Don't know why but the eventListner is not callong the myEvent_eventHandler function. I know that cause i debug the applicaciont with a breakpoint by the function.

        • 1. Re: Anything wrogn with this dispatchEvent?
          John Hall Level 4

          Are both files in the displayList, i.e., visual components? If the one dispatching the event isn't, you'll probably have to create

          an event dispatcher extending IEventDispatcher. Are both components in the same scope? If either of those questions don't make sense, you might want to search around for topics such as "event dispatcher not working" plus there's a good section in the help docs about the DisplayList and how it comes into play.

          • 2. Re: Anything wrogn with this dispatchEvent?
            CoreyRLucier Adobe Employee

            Well... If these are two different files then they are two different components right?

             

            Your addEventListener call is listening for an event on 'File2'. If you wish to listen for the myEvent event on a specific instance you need:

               myFile1.addEventListener(...), where myFile1 is the instance of the component you want to listen to.

             

            If you are wanting to just capture 'myEvent' on the DOM, they what you have there is fine, just look up the interface for addEventListener and pass 'true' for 'useCapture'.

             

            Lastly if you are expecting 'myEvent' to "bubble" up the DOM, then make sure both your File1 instance and File2 are actively on the display list, and that File 2 is somehow an ancestor to File1 in the DOM.

             

            Hope that helps,

             

            Corey