2012-05-16 48 views
0

我正在用Flash Builder 4.6製作一個Flex移動應用程序,並且我想要實現一個函數。flex:文件列表

我有一個聲明:

<s:HTTPService id="getXMLFile" fault="trace('No CCR found!')" result="getPatient(event)" 
         resultFormat="object" url="assets/CCR1.xml"/> 

但這僅指向一個文件,這在需要鍵入 現已如何更改URL,並再次做了要求。

getXMLFile.url = "assets/CCR2.xml"; 
getXMLFile.send(); 

但我想有某種功能檢查中的「資產」包,併爲每個文件的代碼部分的所有文件。所以,我想是這樣的:

for(var file:string in assets) { 
getXMLFile.url = "assets/" + file; 
getXMLFile.send(); 
} 

THX

+0

據我所知,沒有任何工具,這動作。你需要在一些變量(Array)中指定文件名來標記它。 –

回答

0
<fx:Script> 
     <![CDATA[ 
      import mx.rpc.events.FaultEvent; 
      import mx.rpc.events.ResultEvent; 



     //Create one xml having all URL, which you can parse on Flex side. Collect all URL in Array (ex:- fileArray), 
     //than you can loop it. You can call parseXML on creationComplete of your application. 
     private var fileArray:Array = new Array(); 
     private var count:int = 0; 

     //Collect all URL in this fileArray. 
     private function parseXML():void 
     { 
      //parse XML and puch URL in fileArray 
      // xmlLength var is xml length. 
      var xmlLength:int; 
      for(var i:int;i<xmlLength ;i++) 
      { 
       var URL:String = ""; 
       //URL = parse Value from XML; 
       fileArray.push(URL); 
      } 
      sendRequest(); 
     } 

     private function sendRequest():void 
     { 
      getXMLFile.url = fileArray (count); 
      getXMLFile.send(); 
     } 

     private function getPatient(event:ResultEvent):void 
     { 
      //If Success request for Next Patient 
      requestForNextPatient(); 
     } 

     private function faultHandler(event:FaultEvent):void 
     { 
      //If fault request for Next Patient 
      requestForNextPatient(); 
     } 

     private function requestForNextPatient():void 
     { 
      //Request for Next Patient 
      count++; 
      if(count > fileArray.length) 
       sendRequest(): 
     } 

     ]]> 
    </fx:Script> 

    <s:HTTPService id="getXMLFile" fault="faultHandler(event)" result="getPatient(event)" resultFormat="object" /> 

這可能會幫助你.....