6 Replies Latest reply on Sep 18, 2009 4:34 PM by Flex harUI

    ActionScript(.as) dispatchEvent is not captured by addEventListener in .mxml file.

    karnatis

      Hi All,

       

         I'm adding dispatch event in ActionScript, and added that event in .mxml file as below

       

       

        --------------------- ReportSuccessEvent.as (Begin) -----------------------

       

      package com.broad.events
      {
        import flash.events.Event;
        import mx.controls.Alert;
       
        // This custom event should be dispatched if the user
        // successfully logs into the application.

       

        public class ReportSuccessEvent extends Event{   
          public static const REPORT_SUCCESS:String = "reportsuccess"; 
       
          public var inquiry_id:String; 
          
          public function ReportSuccessEvent(inquiry_id:String){
           
            Alert.show("Inside ReportSuccessEvent:",inquiry_id);
            super(ReportSuccessEvent.REPORT_SUCCESS,true,true); //bubble by default  
           
            inquiry_id = inquiry_id;  
           
           
          }
         
          override public function clone():Event{
              return new ReportSuccessEvent(inquiry_id); // bubbling support inside
          }   
         
        }
      }

       

        --------------------- ReportSuccessEvent.as (End) -----------------------

       

      In my controller(action script) I added below code for dispatching this event

       

      dispatchEvent(new ReportSuccessEvent(BroadModel.inquiryConsumer.inquiry_id));

       

      In my .mxml file is having following code

       

      private function initHandler():void
      {
              Alert.show("Inside initHandler");
              addEventListener(ReportSuccessEvent.REPORT_SUCCESS,newReportSucEventHandler);
      }

       

      private function newReportSucEventHandler(event:ReportSuccessEvent):void{   
             
              Alert.show("Inside newReportEventHandler mxml",event.inquiry_id);
              myViewStack.selectedChild = Confirmation;
              newReport.visible=false;

              inquiryIdVal.text = event.inquiry_id;
          }

       

       

        Controller is dispatching event correctly, getting Alert statement from ReportSuccessEvent.as file, but I'm not getting Alert statement from newReportSucEventHandler method. The initHandler is assigned with this event so it should call this method whenever there is dispatcher on this event.

       

        Can someone please let me know what is causing this problem.

       

        Thanks in advance.

       

      Regards,

      Sharath.