Invoking a long-lived process using Remoting

The following Flex code example invokes the FirstAppSolution/PreLoanProcess process.

<?xml version="1.0" encoding="utf-8"?> 
 
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" xmlns="*" backgroundColor="#FFFFFF"  
     creationComplete="initializeChannelSet();"> 
 
<mx:Script> 
         <![CDATA[ 
 
            import mx.controls.Alert; 
            import mx.rpc.events.FaultEvent; 
            import mx.rpc.events.ResultEvent; 
            import flash.net.navigateToURL; 
            import mx.messaging.ChannelSet; 
            import mx.messaging.channels.AMFChannel; 
            import mx.collections.ArrayCollection; 
            import mx.rpc.livecycle.JobId; 
            import mx.rpc.livecycle.JobStatus; 
            import mx.rpc.livecycle.DocumentReference; 
            import mx.formatters.NumberFormatter; 
     
            // Holds the job ID returned by LC.JobManager 
            private var ji:JobId;   
     
            private function initializeChannelSet():void  
             { 
             var cs:ChannelSet= new ChannelSet();  
        cs.addChannel(new AMFChannel("remoting-amf", "http://hiro-xp:8080/remoting/messagebroker/amf"));  
        LC_MortgageApp.setCredentials("tblue", "password"); 
        LC_MortgageApp.channelSet = cs; 
             } 
 
           private function submitApplication():void 
            { 
            //Get the XML data to pass to the LiveCycle ES process 
            var xml:XML = createXML(); 
            var params:Object = new Object(); 
            params["formData"]=xml; 
            LC_MortgageApp.invoke_Async(params); 
            } 
 
            // Handles async call that invokes the long-lived process 
            private function resultHandler(event:ResultEvent):void 
            { 
               ji = event.result as JobId; 
               jobStatusDisplay.text = "Job Status ID: " + ji.jobId as String;  
            } 
 
            private function createXML():XML 
            { 
               //Calculate the Mortgage value to place in the XML data 
               var propertyPrice:String = txtAmount.text ;  
               var name:String = txtName.text ; 
               var phone:String = txtPhone.text ;;  
     
               var model:XML =  
 
                 <LoanApp> 
                          <Name>{name}</Name> 
                          <LoanAmount>{propertyPrice}</LoanAmount> 
                          <PhoneOrEmail>{phone}</PhoneOrEmail>  
                          <ApprovalStatus>PENDING APPROVAL</ApprovalStatus> 
                 </LoanApp> 
     
             return model; 
            } 
     
     
         ]]> 
      </mx:Script> 
     
      <!-- Declare the RemoteObject and set its destination to the mortgage-app remoting endpoint defined in LiveCycle. --> 
      <mx:RemoteObject id="LC_MortgageApp" destination="FirstAppSolution/PreLoanProcess" result="resultHandler(event);"> 
         <mx:method name="invoke_Async" result="resultHandler(event)"/> 
     </mx:RemoteObject> 
 
 
    <mx:Grid x="229" y="186"> 
        <mx:GridRow width="100%" height="100%"> 
            <mx:GridItem width="100%" height="100%"> 
                <mx:Image> 
                    <mx:source>file:///D|/LiveCycle_9/FirstApp/financeCorpLogo.jpg</mx:source> 
                </mx:Image> 
            </mx:GridItem> 
            <mx:GridItem width="100%" height="100%"> 
                <mx:Label text="Flex Loan Application Page" fontSize="20"/> 
            </mx:GridItem> 
            <mx:GridItem width="100%" height="100%"> 
            </mx:GridItem> 
        </mx:GridRow> 
        <mx:GridRow width="100%" height="100%"> 
            <mx:GridItem width="100%" height="100%"> 
                <mx:Label text="Name:" fontSize="12" fontWeight="bold"/> 
            </mx:GridItem> 
            <mx:GridItem width="100%" height="100%"> 
                <mx:TextInput id="txtName"/> 
            </mx:GridItem> 
            <mx:GridItem width="100%" height="100%"> 
                <mx:Button label="Submit Application" click="submitApplication()"/> 
            </mx:GridItem> 
        </mx:GridRow> 
        <mx:GridRow width="100%" height="100%"> 
            <mx:GridItem width="100%" height="100%"> 
                <mx:Label text="Phone/Email:" fontSize="12" fontWeight="bold"/> 
            </mx:GridItem> 
            <mx:GridItem width="100%" height="100%"> 
                <mx:TextInput id="txtPhone"/> 
            </mx:GridItem> 
            <mx:GridItem width="100%" height="100%"> 
            </mx:GridItem> 
        </mx:GridRow> 
        <mx:GridRow width="100%" height="100%"> 
            <mx:GridItem width="100%" height="100%"> 
                <mx:Label text="Amount:" fontSize="12" fontWeight="bold"/> 
            </mx:GridItem> 
            <mx:GridItem width="100%" height="100%"> 
                <mx:TextInput id="txtAmount"/> 
            </mx:GridItem> 
            <mx:GridItem width="100%" height="100%"> 
            </mx:GridItem> 
        </mx:GridRow> 
        <mx:GridRow width="100%" height="100%"> 
            <mx:GridItem width="100%" height="100%"> 
            </mx:GridItem> 
            <mx:GridItem width="100%" height="100%"> 
                <mx:Label text="Label" id="jobStatusDisplay" enabled="true" fontSize="12" fontWeight="bold"/> 
            </mx:GridItem> 
            <mx:GridItem width="100%" height="100%"> 
            </mx:GridItem> 
        </mx:GridRow> 
    </mx:Grid> 
     
</mx:Application>