To load 3 files locally into the Flash Player, one might using something like this manage the sequence after the user has chosen the files...
private function uploadList(evt:Event):void{
var arr:Array = fileReferenceList.fileList;
for each(var item:FileReference in arr){
item.addEventListener(Event.COMPLETE, onFileLoadComplete);
item.load();
}
}
// Step 2 - go ahead and load the file and wait for step 3...this will be called three times in this use-case.
private function onFileLoadComplete(e:Event):void {
var loader:Loader = new Loader();
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onDataLoadComplete);
loader.loadBytes(FileReference(e.target).data);
}
// Step 3 - Flash Player has loaded the file and is ready for processing... // this example is an image being stuffed into a BitmapData object...
private function onDataLoadComplete(e:Event):void {
var bitmapData:BitmapData = Bitmap(e.target.content).bitmapData;
var loader:Loader = Loader(e.target.loader);
...
}
// Step 4 - Where is the filename and file byte size located for each file passing through Step 3?
I've not been able to locate this data in existing objects.
My own resolution....
I stuff the info into a simple dictionary and retrieve it later.
Perhaps there are other solutions out there?
private function onFileLoadComplete(e:Event):void {
if(FileReference(e.target).data.length == 0){
return;
}
var loader:Loader = new Loader();
filenameDict[loader] = String(FileReference(e.target).name);
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onDataLoadComplete);
loader.loadBytes(FileReference(e.target).data);
}
private function onDataLoadComplete(e:Event):void {
var bitmapData:BitmapData = Bitmap(e.target.content).bitmapData;
var loader:Loader = Loader(e.target.loader);
var file:String = filenameDict[loader];
delete filenameDict[loader];