1 Reply Latest reply on Sep 18, 2009 11:18 AM by karnatis

    mxml file listening for event.

    karnatis

      Hi All,

       

         I'm having following code in my project, here Report.mxml file displays to enter user details like (firstname,lastname,city,state,zip etc). After entering user information there is submit button. When user selects this button it needs to submit this data into database and return REPORT_ID back to confirmation state.

       

         My problem is that submitting data into database and getting REPORT_ID is taking some time because of that it is not displaying REPORT_ID in Confirmation viewStack. Rather than getting REPORT_ID from RemoteObject, hardcoding(given in red color) this value in my controller then it is displaying REPORT_ID.

       

        How to wait for event result for displaying confirmation viewStack. Can anyone please suggest me what changes I need to make so that confirmation page will be displayed only after getting REPORT_ID.

       


      ------------------------------- Report.mxml (begin) ----------------

       

       

      <?xml version="1.0" encoding="utf-8"?>
      <mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml" width="100%" height="100%">
         
         
      <mx:Script>
         
          <![CDATA[
          import mx.controls.Alert;
          import com.westernstates.classes.controller.WesternStatesController;
          import com.westernstates.classes.model.WesternStatesModel;
          import com.westernstates.classes.events.*;
         
          private var _inquiryIdTxt:String;
          private var _inquiryIdTxtChanged:Boolean;

       

          public function set inquiryIdTxt(value:String):void
          {
             _inquiryIdTxt = value;
             _inquiryIdTxtChanged = true;
         
             invalidateProperties();
             invalidateSize();
          }

       

          override protected function commitProperties():void
          {
            super.commitProperties();
         
            if (_inquiryIdTxtChanged)
            {
                Alert.show("Inside commitProperties 1",_inquiryIdTxt);
               inquiryIdVal.text = _inquiryIdTxt;
               //inquiryIdVal.text = "1234"
               _inquiryIdTxtChanged = false;
             }
          }
         
          public function init():void{
              Alert.show("Inside newreport init mxml");
             
              myViewStack.selectedChild = newReport;
              Confirmation.visible=false;
                             
              // Reset the value too.
              first_name.text = "";
              last_name.text = "";
              street_address.text = "";
              street_address2.text = "";
              city.text = "";
              state.text = "";
              zip.text = "";
             
          }
             
         
             
              public function submitInquiry(evt:Event):void{
             
              var chk_speed_up:String = "";

       

             
              WesternStatesModel.inquiryConsumer.first_name = first_name.text;
                WesternStatesModel.inquiryConsumer.last_name = last_name.text;
                WesternStatesModel.inquiryConsumer.street_address = street_address.text;
                WesternStatesModel.inquiryConsumer.street_address2 = street_address2.text;
                WesternStatesModel.inquiryConsumer.city = city.text;
                WesternStatesModel.inquiryConsumer.state = state.text;
                WesternStatesModel.inquiryConsumer.zip = zip.text;
                       
               
               
                myViewStack.selectedChild = Confirmation;
                newReport.visible=false;   
             
             
               this.dispatchEvent(new NewReportEvent());        
               
               
                //inquiryIdVal.text = _inquiryIdTxt;
                inquiryIdVal.text = WesternStatesModel.inquiryConsumer.inquiry_id;
             
             
             
              }
             
             
             
          ]]>
      </mx:Script>

       


          <mx:ViewStack id="myViewStack" width="100%" height="100%" creationPolicy="all" >
             
          <mx:Canvas id="newReport" height="100%" width="100%" visible="true">
          <mx:Label x="10" y="10" text="NEW REPORT"  fontSize="18" fontWeight="bold" color="#F07012"/>
          <mx:TitleWindow width="100%" height="100%" layout="absolute" title="Create A New Report" fontWeight="normal" fontSize="13" y="38" x="0">
           <mx:Canvas height="100%" width="100%">
           <mx:VBox width="100%" height="100%">
               <mx:HBox>
                   <mx:Label text="Consumer Information: " fontSize="12" fontWeight="bold" color="#34B05D"/>
               </mx:HBox>
              
               <mx:HBox>
                   <mx:Label text="Report Type: " fontWeight="normal"/>
                   <mx:Label text="Phone" fontWeight="bold"/>
               </mx:HBox>
              
              
               <mx:HBox width="100%">
                   <mx:Label width="25%"  text="First Name:" fontWeight="normal"/>
                   <mx:TextInput width="25%" id="first_name"/>
                   <mx:Label  width="25%" text="Last Name:" fontWeight="normal"/>
                   <mx:TextInput width="25%" id="last_name"/>
               </mx:HBox>
              
               <mx:HBox width="100%">
                   <mx:Label  width="25%" text="Address1: " fontWeight="normal"/>
                   <mx:TextInput width="25%" id="street_address"/>
                   <mx:Label  width="25%" text="Address2:" fontWeight="normal"/>
                   <mx:TextInput width="25%" id="street_address2"/>
               </mx:HBox>
              
               <mx:HBox width="100%">
                   <mx:Label  width="25%" text="City: " fontWeight="normal"/>
                   <mx:TextInput width="25%" id="city"/>
                   <mx:Label  width="25%" text="State:" fontWeight="normal"/>
                   <mx:TextInput width="25%" id="state"/>
               </mx:HBox>
              
               <mx:HBox width="100%">
                   <mx:Label  width="25%" text="Zipcode: " fontWeight="normal"/>
                   <mx:TextInput width="25%" id="zip"/>
                   <mx:Label  width="25%" text="Phone"/>
                   <mx:TextInput width="25%" id="phone"/>
               </mx:HBox>
                      
              
               <mx:HBox width="100%" horizontalAlign="center">
                   <mx:Button label="SUBMIT REPORT" id="submit_search" click="submitInquiry(event)" fillColors="#34B05D"/>
               </mx:HBox>        
             
              </mx:VBox>
          </mx:Canvas>
             
          </mx:TitleWindow>
         
          </mx:Canvas>
         
              <mx:Canvas id="Confirmation" width="100%" height="100%">
         
              <mx:Label x="10" y="10" text="NEW REPORT"  fontSize="18" fontWeight="bold" color="#F07012"/>
              <mx:TitleWindow width="100%" height="132" layout="absolute" title="Create A New Report" fontWeight="normal" fontSize="13" y="38" x="0">
              <mx:VBox width="100%" height="81">
                   <mx:HBox>
                       <mx:Label text="Submission Confirmation:" fontSize="12" fontWeight="bold" color="#34B05D"/>
                   </mx:HBox>
                  
                   <mx:HBox>
                       <mx:Label text="Report has been created successfully with Report ID:"/>
                       <mx:Label id="inquiryIdVal" fontSize="12" fontWeight="bold" color="#34B05D"/>
                   </mx:HBox>
               </mx:VBox>
                      
                  
              </mx:TitleWindow>
             
              </mx:Canvas>
          </mx:ViewStack>

         
      </mx:Canvas>

       

      ------------------------------- Report.mxml (end)   -----------------

       

       

      ------------------------------- NewReportEvent.as( begin) ---------------

       

      package com.westernstates.classes.events
      {
        import flash.events.Event;

       

        // This custom event should be dispatched if the user
        // successfully logs into the application.

       

        public class NewReportEvent extends Event{   
          public static const REPORT:String = "report"; 
       
          
          public function NewReportEvent(){
           
            super(NewReportEvent.REPORT);
          }   
         
        }

      }

       

      ------------------------------- NewReportEvent.as( end)   ----------------

       

      ------------------------------- WesternStatesController.as (begin) ------------

       

         public class WesternStatesController extends UIComponent{

        
          public function WesternStatesController(){
            addEventListener( FlexEvent.CREATION_COMPLETE, init);
          }

       

          // Add event listeners to the system manager so it can handle events
          // of interest bubbling up from anywhere in the application.
          private function init( event:Event ):void{    
           systemManager.addEventListener(NewReportEvent.REPORT, newInquiry, true);
            login(new LoginEvent(LoginEvent.LOGIN));
          }

       

              public function newInquiry(evt:NewReportEvent):void{
                   Alert.show("Inside newInquiry", evt.type);
                   addNewInquiry();
                   //getNewInquiryResult();
             
               }//End of newInquiry

       

               public function addNewInquiry():void
               {
                   ro = new RemoteObject();
                   setUpAmfChannel();
                   ro.destination = "manageInquiryService";
                   ro.addEventListener("fault", faultHandler);      
                   ro.createInquiry.addEventListener("result", getNewInquiryResultHandler);
                   Alert.show("Before addNewInquiry");      
                   ro.createInquiry(WesternStatesModel.inquiry,WesternStatesModel.inquiryConsumer);

             
               }//End of addNewInquiry

       

               public function getNewInquiryResultHandler(event:ResultEvent):void
               {
            
                       WesternStatesModel.inquiryConsumer.inquiry_id = event.result as String;
            
                      //WesternStatesModel.inquiryConsumer.inquiry_id = "09S-1234";  UNCOMMENT     
           
               
               }//End of getNewInquiryResultHandler
         

       

      }

      ------------------------------- WesternStatesController.as (end) ---------------

       

      Thanks in advance.

       

      Regards,

      Sharath.

        • 1. Re: mxml file listening for event.
          karnatis Level 1

          Can someone please tell me how to add event handler to show REPORT_ID before displaying confirmation page. Confirmation page should be displayed once data saved successfully and getting REPORT_ID back from server.

           

          How to set variables for .mxml from action script(.as) file.

           

          Thanks,

          Sharath.