2010-12-14 158 views
1

使用Flash Builder 4(4.1 flex)。 嘗試在我的功能完成運行後創建狀態更改,這將更改屏幕以具有將關閉應用程序的「完成」按鈕。我怎麼能告訴空中應用這樣做?
我發現這個:protected function setState(newState:String):void for AS3但不能在flex 4上工作。它應該在文件數組完成後將狀態更改爲Finished。完成後更改狀態

 private function initiate_download(event:MouseEvent):void 
     { 
      var filearray:Array = new Array(); 
      filearray[0]="00.jpg"; 
      filearray[1]="01.jpg"; 
      filearray[2]="02.jpg"; 
      for (var i:uint; i < filearray.length; i++) { 
       var remoteURL = "http://domain/" + filearray[i]; 
       var localURL = "C:/dir/" + filearray[i]; 
       downloadFile(remoteURL, localURL); 
      } 


      function downloadFile(url, filename) { 
       // Create the stream for the data request 
       var urlStream = new URLStream(); 

       // Used to initiate request for remote file 
       var request = new URLRequest(url); 

       // Create file stream 
       var fileStream = new FileStream(); 

       // Create a reference to a location on disk 
       var file = File.desktopDirectory.resolvePath(filename); 

       // Called as download progresses 
       var writeFile = function() 
       { 
        // Write to file 
        if (urlStream.bytesAvailable > 51200) 
        { 
         var dataBuffer = new ByteArray(); 
         urlStream.readBytes(dataBuffer, 0, urlStream.bytesAvailable); 
         fileStream.writeBytes(dataBuffer, 0, dataBuffer.length); 
        } 
        return true; 
       } 

       // Called when download completes 
       var finishWriteFile = function() 
       { 
        // Write to file 
        if(urlStream.bytesAvailable > 0) 
        { 
         var dataBuffer = new ByteArray(); 
         urlStream.readBytes(dataBuffer, 0, urlStream.bytesAvailable); 
         fileStream.writeBytes(dataBuffer, 0, dataBuffer.length); 
        } 

        // Close streams 
        fileStream.close(); 
        urlStream.close(); 

        return true; 
       } 

       // Initiate download 
       fileStream.openAsync(file, FileMode.WRITE); 
       urlStream.load(request); 

       // Add event listeners 
       urlStream.addEventListener(Event.COMPLETE, finishWriteFile); 
       urlStream.addEventListener(ProgressEvent.PROGRESS, writeFile); 
      } 
    ]]> 
</fx:Script> 
<fx:Declarations> 
    <!-- Place non-visual elements (e.g., services, value objects) here --> 
</fx:Declarations> 
<s:states> 
    <s:State name="Start"/> 
    <s:State name="Finished"/> 
</s:states> 
<mx:Image x="0" y="0" source="background.jpg"/> 
<s:Button x="85" y="85" includeIn="Start" label="Update" id="download" click="initiate_download(event)" color="#FFFFFF" fontSize="30"/> 
<s:Button x="131" y="85" includeIn="Finished" label="Finished" id="closer" click="close_window(event)" color="#FFFFFF" fontSize="30"/> 

回答

0

後您關閉FILESTREAM和URLStream可以更改狀態做

this.currentState = "Finished" 

和關閉按鈕現在應該是可見的。

+0

謝謝,這是完全正確的! 如果你把它放在流關閉之後,在數組的第一個被處理之後它就會改變。我不得不用大型電影文件來測試它。我將努力讓它等到陣列末尾改變。 – mubhcaeb 2010-12-14 20:40:13