4 Replies Latest reply on Aug 3, 2009 5:15 AM by jdb1a1

    A custom event dispatched from custom mxml component isn't triggering the eventListener in parent app

    jdb1a1

      I have a problem I have been trying to resolve now...here is what is going on:

      1) I have a custom event, which is just CustomEvent.as that extends Event. 

      2) when I close a TitleWindow, I call dispatchEvent(myEvent), where myEvent is an instance of the CustomEvent. 

      3) I have verified that the event does get dispatched, because the boolean that returns from the dispatchEvent method is set to "true." 

      4) The eventListeners on the parent app never get called. 

       

      I use this very process on another custom event and eventListener and it works.  It does not work for this one.  Below is my code:

       

      /**The custom event class

      **/

      package me.events.Events

      {

      import flash.events.Event;


      public class CustomEvent extends Event

      {

      public static const WINDOW_CLOSED:String = "windowClosed";

       

      public function CustomEvent(type:String, bubbles:Boolean=true, cancelable:Boolean=false)

      {

      super(type, bubbles, cancelable);


      }

       

       

       

      }

      }


      /**The MXML Component

      **/

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

      <mx:TitleWindow xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" width="400" height="300" title="will be replaced" showCloseButton="true" borderStyle="solid" cornerRadius="0" creationComplete="init();" close="windowCloser();">

      <mx:Label x="10" y="10" text="Project Name:" fontWeight="bold"/>

      <mx:Label x="10" y="50" text="Project Description:" fontWeight="bold"/>

       

      <mx:Script>

      <![CDATA[

      import me.events.CustomEvent;

       

      public static const WINDOW_CLOSED:String = "windowClosed";

       

      public function init():void{}

       

      private function windowCloser():void{

       

      var myEvent:CustomEvent = new CustomEvent();

      dispatchEvent(myEvent);

      PopUpManager.removePopUp(this);

      }

      ]]>

      </mx:Script>

       

       

      </mx:TitleWindow>


      /**The parent application

      **/

      <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationPolicy="all" creationComplete="init();">


      <mx:Script>

      <![CDATA[

       


      private function init():void{

       

       

      this.addEventListener(CustomEvent.WINDOW_CLOSED, myHandler);

       

      intro = model.getIntro();

      PopUpManager.addPopUp(intro,this,true);

      PopUpManager.centerPopUp(intro);

      }


      private function myHandler(e:CustomEvent):void{


      //THIS NEVER GETS CALLED!

      }


      ]]>

      </mx:Script>


      </mx:Application>