【问题标题】:Adobe Flex to pure Action Script. How?Adobe Flex 到纯动作脚本。如何?
【发布时间】:2012-01-10 05:23:11
【问题描述】:

我有以下脚本,它允许通过 PHP 脚本将文件上传到我的 Web 服务器,但我希望将伪代码转换为纯动作脚本。另外,由于某种原因,我的进度条没有显示文件上传的实际进度。

这是 PHP 代码:

<?php

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

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

?>

这是 Adob​​e 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>

【问题讨论】:

  • 既然您什么都不做,为什么还要期待进度条发生变化?
  • 代码有效,似乎 ProgressEvent 有一个事件侦听器,但我猜 PHP 不会报告文件上传进度,因此 Action Script 只看到开头和结尾。我想我只会扔一个微调器。

标签: actionscript-3 apache-flex flex4 flex3 flex4.5


【解决方案1】:

检查此example:您必须设置maximumminimum 属性并在您的fileProgress 函数中调用setProgress

有两种方法可以将 flex 代码转换为纯 as3:
* 在 flex-config.xml 中设置 &lt;keep-generated-actionscript&gt;true&lt;/keep-generated-actionscript&gt;
* 重写你的代码而不使用mxml作为一个纯as3项目

【讨论】:

  • 在上传过程中似乎没有任何东西进入进度条。
【解决方案2】:

这就是我一直在寻找的关于进度条更新的内容。

private function progressHandler(event:ProgressEvent):void 
{ 
    pb.setProgress(event.bytesLoaded, event.bytesTotal); 
}

解决方案的链接。

http://help.adobe.com/en_US/ActionScript/3.0_ProgrammingAS3/WS5b3ccc516d4fbf351e63e3d118a9b90204-7cf6.html

【讨论】:

    猜你喜欢
    • 2013-04-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-04-29
    • 1970-01-01
    • 2013-06-12
    • 2011-02-18
    相关资源
    最近更新 更多