4 Replies Latest reply on Aug 23, 2010 8:40 AM by TonyC_Helyx

    Problem with Custom Event in an ActionScript Component

    TonyC_Helyx

      All,

       

      I am hoping that my issue is quite minor and straight forward to sort out but for the life of me I can't figure it out.

       

      I have written an ActionScrip component that performs some business logic (grographic co-ordinate transformation).  The processing can take a while and relies on making calls to a number of server based process which are all working fine.  The co-ordinate transformation process is started with a call to a public method in the component by the main application.

       

      package helyx
      {

      import flash.events.Event;
      import flash.events.EventDispatcher;

      import mx.controls.Alert;
      import mx.rpc.events.FaultEvent;

      [Event(name="gridConverted_success", type="flash.event.Event")]

       

      public static const SUCCESS:String = "gridConvert_success";
       

      public class GridConverter extends EventDispatcher
      {

       

           private function projectCompleteHandler(event:GeometryServiceEvent):void
             {

                     /* some logic to populate  the _mgrsGrid variable */


              var eventObject:GridConverted = new GridConverted( GridConverted.SUCCESS );
              eventObject.mgrsGrid = _mgrsGrid;
              dispatchEvent(eventObject);
             
             }

      }

       

      In addition to the ActionScript component that performs the transformation logic I have also coded a separate custom event that will return the output of the transformation back to the main application:

       

      package helyx
      {
      import flash.events.Event;

      public class GridConverted extends Event
      {
        public static const SUCCESS:String = "gridConvert_success";
       
        public function GridConverted(type:String, bubbles:Boolean=false, cancelable:Boolean=false)
        {
         super(type, bubbles, cancelable);
        }
       
        public var mgrsGrid:String;
         
      }
      }

       

      In the main application that starts the process I have the following code to add a listener for the event:

       

      private function init():void
         {

           /* other logic... */    

           addEventListener(GridConverter.SUCCESS, gridConvertedHandler);

         }

       

      private function gridConvertedHandler(event:Event):void
         {
          txtGrid.text = gridConverter.mgrsGrid();
         }
        

       

      My problem is that whilst there are no errors thrown the 'gridConvertedHandler' is never called as a result of the 'dispatchEvent()' call.

       

      Grateful for any thoughts....

       

      Tony