十一 162010
 

好吧,我承认我又2B了,用FileReferenceList读取本地多个文件,遍历FileReferenceList.fileList之后,对每个FileReference对象注册了Event.COMPLETE事件,然后执行FileReference.load()方法,在不使用FileReference的情况下是正常的,使用FireReference.upload方法也是正常的。变量也是全局的,囧了。

贴代码,再测测,如果的确是Bug,提交给Adobe去了:

public var importFileList:FileReferenceList = new FileReferenceList();
public var currentFileReference:FileReference = new FileReference();
protected function btnImport_clickHandler(event:MouseEvent):void
{
var imgFilter:FileFilter = new FileFilter("Image Files (png,jpg,gif)","*.png;*.jpg;*.gif;*.jpeg;");
importFileList.addEventListener(Event.SELECT,fileSelectHandler);
importFileList.browse([imgFilter]);
}
private var fileItrIdx:int = 0;
private var fileList:Array;
public function fileSelectHandler(event:Event):void
{
fileList = importFileList.fileList;
fileItrIdx = 0;
itrFile(fileList,fileItrIdx);
}
public function itrFile(fileList:Array,idx:int):void
{
if(idx<importFileList.fileList.length)
{
//importFileList.fileList[idx].addEventListener(Event.COMPLETE,localFileLoadComplete);
//importFileList.fileList[idx].load();
//trace(importFileList.fileList[idx].data);
//以上的代码愣是执行不成功,以下的正常
 (importFileList.fileList[idx] as FileReference).addEventListener(DataEvent.UPLOAD_COMPLETE_DATA,uploadHandler);
(importFileList.fileList[idx] as FileReference).upload(new URLRequest("uploadimg.php"),"img");
}
}
private function uploadHandler(devent:DataEvent):void
{
trace("!!!!!!!!!!!!");
itrFile(fileList,++fileItrIdx);
}
public function localFileLoadComplete(event:Event):void
{
trace("!!!!!!!!!!!!"+event.currentTarget.data.length);
itrFile(fileList,++fileItrIdx);
}

在air下有替代的方法:使用File

 Posted by at 2:08 下午

  4 Responses to “使用FileReferenceList 无法读取多个本地文件的奇异问题”

  1. if(idx<fileList.length)
    {
    fileList[idx].addEventListener(Event.COMPLETE,localFileLoadComplete);
    fileList[idx].load();
    trace(fileList[idx].data);

    既然都已近存到数组里面为何不直接用数组来呢

  2. 嗯,我也碰到了类似的问题,这种情况在WindowedApplication下死活load不了,但在Application下却是正常的,不知道您解决了没有,希望分享一下。。。

  3. @mm15:使用File类就可以了哟

  4. File类就是继续FileReference类的!我这里用File类一样出现Load不了的问题!不知道你用File有没有出现这样的问题?

 Leave a Reply

(required)

(required)

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>