views:

25

answers:

1

I have this code which works fine when selecting a small number of images.

public var fileReferenceList:FileReferenceList;

public function browseFiles(event:Event = null):void 
{
    fileReferenceList= new FileReferenceList();
    fileReferenceList.addEventListener(Event.SELECT,onMultipleFileSelect);
    fileReferenceList.browse("images");
}

private function onMultipleFileSelect(event:Event):void
{
    fileReferenceList.removeEventListener(Event.SELECT,onMultipleFileSelect);
    var fileList:Array = event.target.fileList;
    trace(fileList[0].name);
}

However, when selecting a large number of images (1000+), the fileList isn't initialized yet when the SELECT event is dispatched. Is there a way to wait for the fileList to be initialized?

+1  A: 

Hoo boy. I don't think you will ever get the kind of performance you would like when selecting that many files, but a possible solution would be to check if fileList is null and if it is, call a function that takes the reference to your fileList as a parameter using callLater. In that method, check if it is still null, then call the function again using callLater. No guarantees on this one. It might not work because of the FileReferenceList sandbox requirements of dealing with stuff in UI event handlers. Best of luck.

Wade Mueller
Thanks for the suggestion. Is there a way of using callLater in a .as file?
Maurits de Boer
Yup. Assuming your class has UIComponent in its inheritance hierarchy, you can just call this.callLater(...); If it doesn't, you could do something similar with a Timer.
Wade Mueller
Also, if you found this answer useful, please upvote ;) Thanks.
Wade Mueller