Quick Start: Invoking a short-lived process by passing an unsecure document using LiveCycle Remoting

The following Flex code example invokes a short-lived process named MyApplication/EncryptDocument. (See Invoking LiveCycle using Remoting.)

Hinweis: This quick start invokes a LiveCycle process and uploads an unsecure document. To execute this quick start, LiveCycle has to be configured to upload unsecure documents. For information about how to configure LiveCycle to accept unsecure documents, see Configuring LiveCycle to accept secure and unsecure documents.
<?xml version="1.0" encoding="utf-8"?> 
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" xmlns="*"  
     creationComplete="initializeChannelSet();"> 
     <mx:Script> 
       <![CDATA[ 
     
     import mx.rpc.livecycle.DocumentReference; 
     import flash.net.FileReference; 
     import flash.net.URLRequest; 
     import flash.events.Event; 
     import flash.events.DataEvent; 
     import mx.messaging.ChannelSet; 
     import mx.messaging.channels.AMFChannel;   
     import mx.rpc.events.ResultEvent; 
     import mx.collections.ArrayCollection; 
     import mx.rpc.AsyncToken; 
     
      // Classes used in file retrieval   
     private var fileRef:FileReference = new FileReference(); 
     private var docRef:DocumentReference = new DocumentReference(); 
     private var parentResourcePath:String = "/"; 
     private var serverPort:String = "hiro-xp:8080"; 
     private var now1:Date;     
     private  var cs:ChannelSet 
     
     // Holds information returned from LiveCycle ES 
     [Bindable] 
     public var progressList:ArrayCollection = new ArrayCollection(); 
     
     // Set up channel set to invoke LiveCycle ES. 
     // This must be done before calling any service or process, but only  
     // once for the entire application. 
      private function initializeChannelSet():void { 
       cs = new ChannelSet();  
       cs.addChannel(new AMFChannel("remoting-amf", "http://" + serverPort + "/remoting/messagebroker/amf"));  
       EncryptDocument.setCredentials("administrator", "password"); 
       EncryptDocument.channelSet = cs; 
     } 
     
     // Call this method to upload the file. 
     // This creates a file picker and lets the user select a PDF file to pass to the EncryptDocument process. 
     private function uploadFile():void { 
       fileRef.addEventListener(Event.SELECT, selectHandler); 
       fileRef.browse(); 
     } 
     
      private function selectHandler(event:Event):void 
            { 
            var authTokenService:RemoteObject = new RemoteObject("LC.FileUploadAuthenticator"); 
            authTokenService.addEventListener("result", authTokenReceived); 
            authTokenService.channelSet = cs; 
            authTokenService.getFileUploadToken(); 
            } 
     
    private function authTokenReceived(event:ResultEvent):void 
            { 
            var token:String = event.result as String; 
            var request:URLRequest = DocumentReference.constructRequestForUpload("http://hiro-xp:8080", token); 
             
            try 
            { 
          fileRef.upload(request); 
            } 
            catch (error:Error) 
            { 
            trace("Unable to upload file."); 
            }                               
            } 
 
     
     // Called once the file is completely uploaded. 
     private function completeHandler(event:DataEvent):void {                     
       now1 = new Date(); 
     
       // Set the docRefs url and referenceType parameters 
       docRef.url = event.data as String;       
       docRef.referenceType=DocumentReference.REF_TYPE_URL; 
       executeInvokeProcess();  
     }       
     
     //This method invokes the EncryptDocument process 
     public function executeInvokeProcess():void { 
     
        //Create an Object to store the input value for the EncryptDocument process 
        var params:Object = new Object(); 
        params["inDoc"]=docRef; 
     
        // Invoke the EncryptDocument process 
        var token:AsyncToken;             
        token = EncryptDocument.invoke(params); 
        token.name = name; 
     } 
     
     // This method handles a successful conversion invocation 
     public function handleResult(event:ResultEvent):void 
     { 
           //Retrieve information returned from the service invocation 
         var token:AsyncToken = event.token;         
         var res:Object = event.result; 
         var dr:DocumentReference = res["outDoc"] as DocumentReference; 
         var now2:Date = new Date(); 
     
         // These fields map to columns in the DataGrid 
         var progObject:Object = new Object(); 
         progObject.filename = token.name; 
         progObject.timing = (now2.time - now1.time).toString(); 
         progObject.state = "Success"; 
         progObject.link = "<a href=" + dr.url + "> open </a>"; 
         progressList.addItem(progObject); 
     } 
     
     private function resultHandler(event:ResultEvent):void { 
       // Do anything else here. 
     } 
 
       ]]> 
     </mx:Script> 
     <mx:RemoteObject id="EncryptDocument" destination="MyApplication/EncryptDocument" result="resultHandler(event);"> 
         <mx:method name="invoke" result="handleResult(event)"/> 
     </mx:RemoteObject> 
     
     <!--//This consists of what is displayed on the webpage--> 
     <mx:Panel id="lcPanel" title="EncryptDocument LiveCycle Remoting Example"  
          height="25%" width="25%" paddingTop="10" paddingLeft="10" paddingRight="10"  
          paddingBottom="10"> 
        <mx:Label width="100%" color="blue" 
               text="Select a PDF file to pass to the EncryptDocument process"/>  
       <mx:DataGrid x="10" y="0" width="500" id="idProgress" editable="false"  
          dataProvider="{progressList}" height="231" selectable="false" > 
         <mx:columns> 
           <mx:DataGridColumn headerText="Filename" width="200" dataField="filename" editable="false"/> 
           <mx:DataGridColumn headerText="State" width="75" dataField="state" editable="false"/> 
           <mx:DataGridColumn headerText="Timing" width="75" dataField="timing" editable="false"/> 
           <mx:DataGridColumn headerText="Click to Open" dataField="link" editable="false" > 
            <mx:itemRenderer> 
               <mx:Component> 
                  <mx:Text x="0" y="0" width="100%" htmlText="{data.link}"/> 
               </mx:Component> 
            </mx:itemRenderer> 
           </mx:DataGridColumn> 
         </mx:columns> 
       </mx:DataGrid> 
       <mx:Button label="Select File" click="uploadFile()" /> 
     </mx:Panel> 
</mx:Application>