Today I noticed a strange thing in Flex. Let me explain the problem.
I created FileReferenceList. I added a eventListener to that FileReferenceList that returns me the list of files that the user selects. This is the code:
private function openFileReference():void{
var flr:FileReferenceList = new FileReferenceList();
flr.addEventListener(Event.SELECT, onFrlResult);
flr.browse();}
private function onFrlResult(event:Event):void{
trace("Select event: "+event.target);
}
When I tested the code I noticed that the function wasn’t called.
After that I tried to change the “FileReferenceList” to a “FileReference” and for the rest I kept the function the same. In this case my function “onFrlResult” was called. After some try and error I found the solution.
You can create a FileReference in a function but this is different with a FileReferenceList. You have to declare a variable with the type FileReferenceList outside the function. The final code will look like this:
private var flr:FileReferenceList;
private function openFileReference():void{
this.flr = new FileReferenceList();
this.flr.addEventListener(Event.SELECT, onFrlResult);
this.flr.browse();
}
private function onFrlResult(event:Event):void{
trace("Select event: "+event.target);
}
I’m not sure if it is a problem/bug. Maybe there is a reason that you can’t create a variable with the type FileReferenceList inside a function. If someone knows why than please share it with me and leave a comment
Leave a Reply to Aris Cancel reply