Why is TextInput updating after I hit fileReferencer.browse button a second time
In Flex 4, I am trying to make a simple bro开发者_开发问答wse button update the text field of an TextInput object with the file name that the browse button gets. It doesn't have to be the full path, all I want is the file name to show up. It only shows up after hitting the browse button for a second time, not after I have selected my file the first time. Here is my code:
import flash.net.FileReference;
private var fileReferencer:FileReference = new FileReference();
private var excelFilter:FileFilter = new FileFilter("*.xlsx", "*.xlsx;*.xls;");
protected var fileName:String = new String("");
protected function BrowseButton_clickHandler(event:MouseEvent):void
{
fileReferencer.browse([excelFilter]);
fileName = fileReferencer.name;
fileInputAddress.text = fileName;
}
So to recap, the file name is only shown in my TextInput box upon hitting the browse button a second time.
What am I doing wrong?
Flash Player is completely asynchronous. So you can't get file name right after calling fileReferencer.browse()
. That's why you have a name from the past call. To fix your code you should subscribe on select
and cancel
events and change the text after select
event only (see the documentation).
精彩评论