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