Flash AS3 Tutorials Center | Interesting Flash Animation Tutorials | Valuing Flash Animation Tutorials | Flash ActionScript and Animation Home

AS3 Beginner Tutorials | AS3 Basic Lessons | AS3 Valuing Courses | AS3 Components Tutorials | AS3 and PHP Interaction Tutorials
AS3 Practical Tutorials | AS3 Animation Techniques | AS3 Transition Effects Tutorials | AS3 Download Upload Files | AS3 Particle Systems
Communication Between Flash Movies with AS3 | AS3 and JavaScript interaction | AS3 Matrix Transformation | AS3 Physics Simulation Tutorials

Flash ActionScript Uploading File - Filter File Extensions Display in Browse Window

In previous Flash ActionScript upload files tutorials, all files with any types will display in the Browse Window when user click on the Browse button. In most cases, you may only want some file types display in the Browse Window that you want user to upload.

Please update flash player to view this Flash ActionScript tutorial!

Flash Tutorial Content:

The Flash ActionScript can get this result by:

  • specify the filtered file types that will be used, and then
  • pass the filtered file types as an array to the browse() method.

Flash ActionScript Codes:

// Set text field to empty
// This use to detect user select file or not
output_txt.text="";

 

// Create a new instance of the FileReference class to work with.
var myfileReference:FileReference = new FileReference();

 

// Listen to when Save button has been clicked on
myfileReference.addEventListener(Event.SELECT, fileSelected);

 

// Create a FileFilter object filters for files with specified file extensions
// i.e. only this file extension will display in Browse Window
// The following line of code will allow .png, gif, jpg to display in Browse Window
// var fileFilter:FileFilter = new FileFilter("Images", "*.png;*.gif;*.jpg");
// The following line of code will only display .jpg in Browse Window
var fileFilter:FileFilter = new FileFilter("Images", "*.jpg");

 

function fileSelected(evt:Event):void {

output_txt.text = "File selected upload: " + evt.target.name;
}

 

function browseFile (event:MouseEvent):void {

output2_txt.text = "";

 

// Use browse( ) method of a FileReference object to open a
// dialog box to browse local disks for a file.
myfileReference.browse([fileFilter]);


}

 

// Create a new URLRequest instance sending data to "upload.php"
var myRequest:URLRequest = new URLRequest("upload.php");

 

function uploadFile (event:MouseEvent):void {

// Reset the Alert text field to empty
output2_txt.text ="";

if (output_txt.text.length > 0) {

// Call the upload( ) method of FileReference object to upload a file
myfileReference.upload(myRequest);

} else {

// Alert user to select a file to upload
output2_txt.text = "Please browse for file to upload!";
}

}

// Hook up the button with the function browseFile
browse_btn.addEventListener(MouseEvent.CLICK, browseFile);

Download Flash Source File:

Flash Source File as3-upload-file-04.fla

Remarks:

This Flash ActionScript uploading file extension shows how to filter file types to display on Browse Window. However users can enter the file name if the file really exist.