Progress bar pourcentage uploadé
Bonjour,
voila j'ai un problème. J'ai un programme qui me permet lorsque je clique sur un bouton, de parcourir et d'envoyé une image dans un dossier sur mon serveur. Pour cela, j'ai un programme principal:
Code:
1 2 3 4 5 6 7
| var monUp:ImageUpload = new ImageUpload("images");
private function lancerUpload(e:MouseEvent):void
{
monUp.init();
} |
et une classe ImageUpload.as :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136
| package {
import flash.events.DataEvent;
....
public class ImageUpload extends EventDispatcher {
static public var START_UP:String = "Upload démarre";
static public var END_UP:String = "Fin de l'upload";
static public var ANNUL_UP:String = "Cancel de l'utilisateur";
static public var SERVEUR_RETOUR:String="Le serveur a répondu";
static public var POURCENT:Number;
private var scriptURL:URLRequest;
private var scriptURL2:URLRequest;
private var file:FileReference;
private var dest:String; //dossier de destination
private var rootInfo:TextField;
private var _messServeur:String;
private const imagesFilter:FileFilter = new FileFilter("Images", "*.jpg;*.gif;*.png;*.bmp");
private var _nameImage:String;
public function ImageUpload(dir:String) {
dest = dir;
}
public function init():void
{
scriptURL = new URLRequest();
scriptURL.url = "*********/upload.php";
scriptURL.method = URLRequestMethod.POST;
var variables:URLVariables = new URLVariables();
variables.doss = dest;
scriptURL.data = variables;
file = new FileReference();
file.addEventListener(Event.SELECT, onSelectImage);
configureListeners(file);
file.browse([imagesFilter]);
}
private function configureListeners(dispatcher:IEventDispatcher):void {
dispatcher.addEventListener(Event.CANCEL, onAnnul);
dispatcher.addEventListener(Event.COMPLETE, onUploadComplet);
dispatcher.addEventListener(HTTPStatusEvent.HTTP_STATUS, httpStatusHandler);
dispatcher.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler);
dispatcher.addEventListener(Event.OPEN, onDebutUpload);
dispatcher.addEventListener(ProgressEvent.PROGRESS, onProgess);
dispatcher.addEventListener(SecurityErrorEvent.SECURITY_ERROR, securityErrorHandler);
dispatcher.addEventListener(Event.SELECT, onSelectImage);
dispatcher.addEventListener(DataEvent.UPLOAD_COMPLETE_DATA,rapportChargement);
}
private function removeListeners(dispatcher:IEventDispatcher):void {
dispatcher.removeEventListener(Event.CANCEL, onAnnul);
dispatcher.removeEventListener(Event.COMPLETE, onUploadComplet);
dispatcher.removeEventListener(HTTPStatusEvent.HTTP_STATUS, httpStatusHandler);
dispatcher.removeEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler);
dispatcher.removeEventListener(Event.OPEN, onDebutUpload);
dispatcher.removeEventListener(ProgressEvent.PROGRESS, onProgess);
dispatcher.removeEventListener(SecurityErrorEvent.SECURITY_ERROR, securityErrorHandler);
dispatcher.removeEventListener(Event.SELECT, onSelectImage);
}
private function onAnnul(event:Event):void {
dispatchEvent(new Event(ImageUpload.ANNUL_UP));
}
private function onUploadComplet(event:Event):void {
removeListeners(file);
dispatchEvent(new Event(ImageUpload.END_UP));
}
private function rapportChargement(event:DataEvent):void {
_messServeur=String(event.data);
file.removeEventListener(DataEvent.UPLOAD_COMPLETE_DATA,rapportChargement);
dispatchEvent(new Event(ImageUpload.SERVEUR_RETOUR));
}
public function get messServeur():String
{
return _messServeur;
}
private function httpStatusHandler(event:HTTPStatusEvent):void {
trace("httpStatusHandler: " + event);
}
private function ioErrorHandler(event:IOErrorEvent):void {
trace("ioErrorHandler: " + event);
alert.show(String(event));
}
private function onDebutUpload(event:Event):void {
dispatchEvent(new Event(ImageUpload.START_UP));
}
private function onProgess(event:ProgressEvent):void {
var file:FileReference = FileReference(event.target);
ImageUpload.POURCENT = (event.bytesLoaded/event.bytesTotal)*100;
}
private function securityErrorHandler(event:SecurityErrorEvent):void {
trace("securityErrorHandler: " + event);
}
private function onSelectImage(event:Event):void {
file = FileReference(event.target);
_nameImage= file.name;
file.upload(scriptURL);
}
public function get nameImage():String
{
return _nameImage;
}
}
} |
Je voudrais afficher une barre de progression, qui indique le pourcentage uploader.Donc pour cela je doit créer une progress bar. Dans ma classe, j'ai mon "ImageUpload.POURCENT" qui me renvoie le pourcentage uploadé.
Le problème c'est que j'arrive pas depuis mon fichier principal a afficher ce pourcentage dans la progresse bar. J'ai bien essayé d'utilisé setprogress dans ma progress bar ou d'autre élément mais rien n'y fait.
Quelqu'un a une idée?