ProblemYou want to detect when the user has selected a file from the browse dialog box. SolutionListen for a select event. Listen for a cancel event to determine if and when the user clicks the Cancel button. DiscussionWhen the user selects a file and clicks the Open button from a browse dialog box, the FileReference object dispatches a select event of type Event. You can use the Event.SELECT constant to add a listener, as follows: fileReference.addEventListener(Event.SELECT, onSelectFile); When the user has selected a file, the details of that file are immediately available (name, size, createdDate, etc.). For example, as soon as a FileReference object dispatches a SELECT event you can retrieve the filename, as in the following example: selectedFileTextField.text = fileReference.name; When the user clicks the Cancel button from a browse dialog box, the FileReference object dispatches a cancel event of type Event. You can use the Event.CANCEL constant to add a listener, as follows: fileReference.addEventListener(Event.CANCEL, onCancelBrowse); The select and cancel events also work for FileReferenceList objects. See AlsoRecipe 23.7 |