0

我想创建多个文件上传 Flash 应用程序。我需要知道如何同时使用多个进度条跟踪多个文件上传。

4

2 回答 2

1

这是演示。主要思想是创建一个包含 FileReference 或 URLLoader 和进度指示器的类。

主要作为:

package 
{
    import flash.display.*;
    import flash.events.*;
    import flash.text.*;

    public class Main extends Sprite 
    {
        public function Main():void 
        {
            if (stage) init();
            else addEventListener(Event.ADDED_TO_STAGE, init);
        }

        private function init(e:Event = null):void 
        {
            removeEventListener(Event.ADDED_TO_STAGE, init);

            var btnText:TextField = new TextField;
            btnText.autoSize = TextFieldAutoSize.LEFT;
            btnText.text = "Click to upload";
            var btn:SimpleButton = new SimpleButton(btnText, btnText, btnText, btnText);
            addChild(btn);

            btn.addEventListener(MouseEvent.CLICK, onBtnClick);
        }

        private function onBtnClick(e:MouseEvent):void 
        {
            var uploader:Uploader = new Uploader("http://www.yahoo.com/");
            uploader.y = this.height;
            addChild(uploader);
        }
    }

}

上传者.as:

package  
{
    import flash.display.*;
    import flash.events.*;
    import flash.net.*;
    import flash.text.*;

    public class Uploader extends Sprite 
    {
        private var url:String;
        private var fileRef:FileReference;
        private var text:TextField = new TextField;

        public function Uploader(url:String ) 
        {
            this.url = url;

            text.autoSize = TextFieldAutoSize.LEFT;
            text.text = "..."
            addChild(text);

            fileRef = new FileReference();
            fileRef.browse();
            fileRef.addEventListener(Event.SELECT, onSelect);
        }

        private function onSelect(e:Event):void 
        {
            text.text = fileRef.name + " : starting upload";

            var req:URLRequest = new URLRequest(url);
            req.method = URLRequestMethod.POST;

            fileRef.upload(req, fileRef.name);
            fileRef.addEventListener(ProgressEvent.PROGRESS, onProgress);
            fileRef.addEventListener(Event.COMPLETE, onComplete);
            fileRef.addEventListener(IOErrorEvent.IO_ERROR, onError);
        }

        private function onError(e:IOErrorEvent):void 
        {
            text.text = fileRef.name + " :" + e.text;
        }

        private function onComplete(e:Event):void 
        {
            text.text = fileRef.name + " : Complete";
        }

        private function onProgress(e:ProgressEvent):void 
        {
            text.text = fileRef.name + " : " + e.bytesLoaded + "/" + e.bytesTotal;
        }

    }

}
于 2013-06-06T16:35:21.673 回答
0

创建一个 URLLoader 并监听 PROGRESS 事件。

于 2013-06-04T16:01:53.143 回答