2012-01-10 20 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