flash cs4 file reference. Event.COMPLETE not called on a MAC,
I am working with a fileReference, however I'm having issues running on Safari on a MAC...
EDIT: The below example also doesnt work on Safari on a MAC...
http://www.permadi.com/blog/2010/06/flash-as3-using-filereference-to-load-files-example-for-flash-cs4-and-above/
The workflow on a PC runs as such:
- Create file reference
- attach
addEventListener
forEvent.SELECT
andEvent.COMPLETE
- call the
browse()
method
On a PC, Event.SELECT
is fired when a file has been selected.
Event.COMPLETE
is fired when the file data is availab开发者_运维百科le to flash. If I select an 500 MB file, it takes a few seconds before Event.COMPLETE
is fired. If I attempt to access the file data properties (such as reading the data stream) before Event.COMPLETE
is fired, I receive null reference errors...
So far so good...
However, on a MAC (specifically Safari, not tested other browsers), the Event.COMPLETE
is not fired.
I have checked the Adobe docs, which say Event.COMPLETE
is fired when the upload is completed. So why does it get fired on windows when the fileReference
has parsed the file, but the upload method has not yet been called...
Can anyone help?
Here's snippets of the code I am working on:
public function browseFile(target:Object):void
{
var imagesFilter:FileFilter = new FileFilter("Allowed files", "*.jpg;*.bmp;*.flv;");
fileReference.browse([imagesFilter]);
fileReference.addEventListener(Event.SELECT, fileSelect);
fileReference.addEventListener(Event.COMPLETE, fileSelectComplete);
}
private function fileSelect(event:Event):void
{
// update label - IMPORTANT for large files as there's a delay while flash parses file, before control is handed back to this script...
setStatusLabel("...loading file");
var fileReference:FileReference = event.target as FileReference;
fileReference.addEventListener(Event.COMPLETE, fileSelectComplete);
// load the file into the fileReference object
fileReference.load();
}
// Called when upload file has been processed by flash (a few secs for large files, or fileRef.data is null...)
private function fileSelectComplete(event:Event):void
{
var fileReference:FileReference=event.target as FileReference;
trace("ready to do things - but not fired on Safari on a MAC ");
}
definitely a bug of sdk 3.4 I have a work round here
var fr:FileReference = e.currentTarget as FileReference;
fr.addEventListener(Event.COMPLETE, onModelDone);
fr.addEventListener(ProgressEvent.PROGRESS, onProgress);
// trace("loading...");
setTimeout(function():void {fr.load()}, 1); // put it here for delay
I tried it on sdk3.9 it still the same, so I filed a bug here: https://bugbase.adobe.com/index.cfm?event=bug&id=3687113
I seem to have gotten it working, using DataEvent.UPLOAD_COMPLETE_DATA instead of Event.COMPLETE.
var fileRef:FileReference = new FileReference();
fileRef.addEventListener(Event.SELECT, onFileSelected);
fileRef.addEventListener(DataEvent.UPLOAD_COMPLETE_DATA, onUploadComplete);
function onFileSelected(event:Event):void {
statusBar.text = "File upload started";
fileRef.upload(FILE_UPLOAD_URL);
};
function onUploadComplete(event:Event):void {
statusBar.text = "File upload completed";
};
精彩评论