0
我想创建多个文件上传的Flash应用程序。我需要知道如何使用多个进度条同时跟踪多个文件上传。跟踪多文件上传与多个进度条与AS 3.0
我想创建多个文件上传的Flash应用程序。我需要知道如何使用多个进度条同时跟踪多个文件上传。跟踪多文件上传与多个进度条与AS 3.0
创建URLLoader和听取进度事件。
这里是演示。 主要想法是创建一个包含FileReference或URLLoader和进度指示器的类。
Main.as:
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);
}
}
}
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;
}
}
}
谢谢您的答复。但我有5个文件要上传。我需要同时进行每次上传的进度条。例如,5个文件正在上传,我想看到5个进度条。我怎样才能将每个文件与进度条相关联。 –
创建五个URLLoaders并聆听每个... – romamik