2012-01-10 52 views
0

我有以下腳本,它允許通過PHP腳本將文件上傳到我的Web服務器,但我希望將僞代碼轉換爲純動作腳本。另外,出於某種原因,我的進度欄不顯示文件上傳的實際進度。Adob​​e Flex轉爲純動作腳本。怎麼樣?

這裏是PHP代碼:

<?php 

$tempFile = $_FILES['Filedata']['tmp_name']; 
$fileName = $_FILES['Filedata']['name']; 
$fileSize = $_FILES['Filedata']['size']; 

move_uploaded_file($tempFile, "./" . $fileName); 

?> 

這裏是Adobe Flex的代碼:

<?xml version="1.0" encoding="utf-8"?> 
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 
       xmlns:s="library://ns.adobe.com/flex/spark" 
       xmlns:mx="library://ns.adobe.com/flex/mx" 
       width="225" height="178" minWidth="955" minHeight="600"> 
    <fx:Declarations> 

    </fx:Declarations> 

<fx:Script> 
    <![CDATA[ 

     import flash.net.FileReference; 
     public var fileRef:FileReference = new FileReference(); 
     public function uploadDialog(e:MouseEvent):void{ 
      errLabel.text=""; 
      var imgType:FileFilter = new FileFilter("Images (*.GIF,*.JPG,*.PNG)","*.gif;*.jpg;*.png"); 
      var filterArray:Array=new Array(imgType); 
      fileRef.browse(filterArray); 
      fileRef.addEventListener(Event.SELECT,fileSelect); 
      fileRef.addEventListener(ProgressEvent.PROGRESS,fileProgress); 
      fileRef.addEventListener(Event.COMPLETE,fileComplete); 
     } 

     public function fileSelect(e:Event):void{ 
      var fileURL:URLRequest = new URLRequest("upload.php"); 
      try 
      { 
       //filepath.text=fileRef.name; 
       fileRef.upload(fileURL); 
      } 
      catch (err:Error) 
      { 
       errLabel.text="Unable to Upload File....."; 
      } 
     } 

     public function fileProgress(e:ProgressEvent):void 
     { 
      progBar.visible=true; 
     } 

     public function fileComplete(e:Event):void{ 

      errLabel.text="File Uploaded Sucessfully....." 
      progBar.visible=false; 

     } 

    ]]> 
</fx:Script> 


    <s:Label x="10" y="10" click="uploadDialog(event)" text="Upload ..."/> 
    <mx:ProgressBar id="progBar" x="10" y="26"/> 
    <s:Label id="errLabel" x="10" y="108" width="200" text="..."/> 

</s:Application> 
+0

你爲什麼期待您的進度條來改變,因爲你什麼都不做是什麼? – 2012-01-10 05:59:19

+0

代碼工作,似乎有ProgressEvent的事件監聽器,但我猜PHP不會報告文件上傳進度,因此Action Script只能看到開始和結束。我想我只會拋出一個微調。 – ASPiRE 2012-01-10 14:48:51

回答

0

檢查這個example:你必須設置maximumminimum性能和呼叫setProgressfileProgress功能

有兩種方式把Flex代碼爲純AS3:
*設置<keep-generated-actionscript>true</keep-generated-actionscript>在柔性-config.xml中
*重寫代碼,而無需使用MXML作爲一個純粹的AS3項目

+0

在上傳過程中似乎沒有提供進度條。 – ASPiRE 2012-01-10 14:50:23