flash cs4文件参考。没有在MAC上调用Event.COMPLETE,

时间:2010-06-16 17:52:18

标签: flash actionscript-3 filereference

我正在使用fileReference,但是我在MAC上的Safari上运行时遇到了问题...

修改 以下示例也不适用于MAC上的Safari ...

http://www.permadi.com/blog/2010/06/flash-as3-using-filereference-to-load-files-example-for-flash-cs4-and-above/

PC上的工作流程如下:

  1. 创建文件参考
  2. addEventListenerEvent.SELECT
  3. 附上Event.COMPLETE
  4. 调用browse()方法
  5. 在PC上,选择文件时会触发Event.SELECT。 当文件数据可用于Flash时会触发Event.COMPLETE。如果我选择500 MB文件,则在Event.COMPLETE被触发之前需要几秒钟。如果我在Event.COMPLETE被触发之前尝试访问文件数据属性(例如读取数据流),则会收到空引用错误...

    到目前为止一直很好......

    但是,在MAC(特别是Safari,未经测试的其他浏览器)上,Event.COMPLETE未被触发。

    我检查了Adobe文档,其中说上传完成时会触发Event.COMPLETE。所以为什么fileReference解析文件时会在Windows上被触发,但尚未调用上传方法......

    有人可以帮忙吗?

    以下是我正在处理的代码的片段:

    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 ");
    }
    

2 个答案:

答案 0 :(得分:1)

绝对是sdk 3.4的错误我在这里工作了

        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

我在sdk3.9上尝试过它仍然是一样的,所以我在这里提交了一个错误: https://bugbase.adobe.com/index.cfm?event=bug&id=3687113

答案 1 :(得分:0)

我似乎已经使用DataEvent.UPLOAD_COMPLETE_DATA而不是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";
};