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
| <?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" width="100%" height="100%" backgroundColor="white">
<mx:Script>
<![CDATA[
import flash.events.*;
import flash.net.FileReference;
import flash.net.navigateToURL;
import flash.net.FileFilter;
import flash.net.URLLoader;
import flash.net.URLRequest;
import org.flashdevelop.utils.FlashConnect;
import mx.core.*;
private var file:FileReference;
private var urlChargement:String = "http://localhost/modules/testmodule/classes/upload.php";
private var envoi:URLRequest;
/*----------------Selection du fichier----------------------*/
public function initForm():void
{
file = new FileReference();
// file.addEventListener(Event.SELECT, Delegate.pass(selection, file));
file.addEventListener(ProgressEvent.PROGRESS, progressHandler);
file.addEventListener(Event.COMPLETE, receptionMessages);
file.addEventListener(IOErrorEvent.IO_ERROR,IO_ERREUR );
file.browse();
progressBar.setProgress(0, 100);
}
private function selection(event:Event,f:FileReference):void
{
fichier.text = f.name;
}
/*private function getTypes():Array {
var filtresImages:FileFilter = new FileFilter("Images (*.jpg, *.jpeg, *.gif, *.png)", "*.jpg;*.jpeg;*.gif;*.png");
var allTypes:Array = new Array(filtresImages);
return allTypes;
}*/
/*---------------Envoi du fichier----------------*/
private function envoiFichier():void
{
var variables:URLLoader = new URLLoader();
variables.dataFormat = URLLoaderDataFormat.VARIABLES;
variables.addEventListener(Event.COMPLETE, receptionMessages);
envoi = new URLRequest(urlChargement);
envoi.method = URLRequestMethod.POST;
envoi.requestHeaders;
envoi.data = new URLVariables('nom=' + fichier.text);
file.upload(envoi,'data',false);
variables.load(envoi);
FlashConnect.atrace("envoi du fichier : " + fichier.text);
}
private function progressHandler(event:ProgressEvent):void {
progressBar.setProgress(event.bytesLoaded, event.bytesTotal);
progressBar.label = ((event.bytesLoaded * 100) / event.bytesTotal).toString()+"%";
}
/*--------------reception de messages-------------*/
private function IO_ERREUR(event:Event):void{
t.text = "Event.OPEN: " + event.toString() ;
}
private function receptionMessages(event:Event):void
{
var loader2:URLLoader = URLLoader(event.target);
t.text = loader2.data;
}
]]>
</mx:Script>
<mx:VBox percentWidth="100" percentHeight="100">
<mx:HBox horizontalCenter="0">
<mx:Label text="1 - Recherche du fichier sur votre ordinateur " fontSize="10" />
<mx:Button label="parcourir" click="initForm()"/>
</mx:HBox>
<mx:HBox>
<mx:Label text="2 - renommer le fichier si besoin.."/>
<mx:TextInput id="fichier" width="200" />
</mx:HBox>
<mx:HBox>
<mx:Label text="3 - envoi du fichier vers le serveur "/>
<mx:Button label="envoyer" click="envoiFichier()" />
</mx:HBox>
<mx:HBox>
<mx:Text id="t" text="-----"/>
<mx:FormItem label="Progression">
<mx:ProgressBar id="progressBar" mode="manual" label = "chargement 0%" />
</mx:FormItem>
</mx:HBox>
</mx:VBox>
</mx:Application> |