The FileReferenceList Class


The FileReferenceList Class

The FileReferenceList class was created to allow users to browse for and upload multiple files. It is important to note that even though you can use this object to select and upload multiple files, the files themselves must still be uploaded individually.

It is important when using this class to import it first at the beginning of your script, like this:

 import flash.net.FileReferenceList; 

To instantiate a new instance of the FileReference object, use this code as a template:

 var myFile_frl:FileReferenceList = new FileReferenceList(); 

Properties

fileList

Availability: FP:8, AS:1.0

Generic Template: myFile_frl.fileList;

Description:

This property is an array file of different FileReference objects.

Example:

This example will allow the user to select multiple files, and when the user clicks Open, all the properties of each FileReference will be sent to the Output panel:

 import flash.net.FileReferenceList; //the listener object var list_obj:Object = new Object(); //when the user has finished selecting the files list_obj.onSelect = function(fileRefList:FileReferenceList){     var list_array = fileRefList.fileList;     var tLength:Number = list_array.length;     var i = 0;     while(i<tLength){         var file = list_array[i];         for(prop in file){             trace(prop + " - " + file[prop]);         }         i++;     } } //FileReferenceList object var file_frl:FileReferenceList = new FileReferenceList(); //add the listener file_frl.addListener(list_obj); //browse file_frl.browse(); 

Methods

addListener

Availability: FP:8, AS:1.0

Generic Template: myFile_frl.addListener(listener);

Parameter:

  • listener This is the object that listens for the events of a FileReference object.

Description:

This method will add an event listener to an instance of the FileReferenceList object.

Example:

This example will create a FileReferenceList object, and automatically call the browse method when you test it. After you select a file and click Open, all the properties from the first file will be sent to the Output panel:

 import flash.net.FileReferenceList; //the FileReferenceList object var file_frl:FileReferenceList = new FileReferenceList(); //object for listening to for FileReference events var list_obj:Object = new Object(); //the event for when a user selects the file(s) and hits open list_obj.onSelect =function(fileRefList:FileReferenceList){     trace("name: "+fileRefList.fileList[0].name);     trace("creation date: "+fileRefList.fileList[0].creationDate);     trace("modification date: "+fileRefList.fileList[0].modificationDate);     trace("type: "+fileRefList.fileList[0].type);     trace("size in bytes: "+fileRefList.fileList[0].size);     trace("creator: "+fileRefList.fileList[0].creator); } //add the listener to the FileReference object file_frl.addListener(list_obj); //browse file_frl.browse(); 

browse

Availability: FP:8, AS:1.0

Generic Template: myFile_frl.browse(types);

Parameter:

  • types This array is an optional parameter that will allow you to set certain file types to be able to be selected. Inside this array are objects that have three properties:

    • description This is what appears to the user in the file type drop-down.

    • extensions These are the different file type extensions you want to allow, each separated by a semicolon, like this: "*.jpg;*.png;*.gif".

    • macType This a Macintosh-specific property that will allow you to limit files to macType.

Description:

This method will allow end users to browse for files on their local system and have them returned to Flash.

Example:

This example will create a FileReferenceList object and automatically call the browse method when you test it. It will limit the files to just a few image types. After you select the file(s) and click Open, all the properties of the first file will be sent to the Output panel:

[View full width]

import flash.net.FileReferenceList; //the FileReferenceList object var file_frl:FileReferenceList = new FileReferenceList(); //object for listening to for FileReference events var list_obj:Object = new Object(); //the event for when a user selects the file(s) and hits open list_obj.onSelect =function(fileRefList:FileReferenceList){ trace("name: "+fileRefList.fileList[0].name); trace("creation date: "+fileRefList.fileList[0].creationDate); trace("modification date: "+fileRefList.fileList[0].modificationDate); trace("type: "+fileRefList.fileList[0].type); trace("size in bytes: "+fileRefList.fileList[0].size); trace("creator: "+fileRefList.fileList[0].creator); } //add the listener to the FileReference object file_frl.addListener(list_obj); //the file types you want var fileTypes:Array = new Array({description: "Images - .jpg, .gif, .png", extension: " * .jpg;*.gif;*.png"}); //browse file_frl.browse(fileTypes);

removeListener

Availability: FP:8, AS:1.0

Generic Template: myFile_frs.removeListener(listener);

Parameter:

  • listener This is the object that listens for the events of a FileReferenceList object.

Returns: Boolean

If the listener is removed successfully, true is returned; otherwise, false is returned.

Description:

This method will remove an event listener from an instance of the FileReferenceList object.

Example:

This example will create a FileReferenceList object and automatically call the browse method when you test it. After you select the file(s) and click Open, the name property of the first file will be sent to the Output panel, and the listener will be removed:

 import flash.net.FileReferenceList; //the FileReferenceList object var file_frl:FileReferenceList = new FileReferenceList(); //object for listening to for FileReference events var list_obj:Object = new Object(); //the event for when a user selects a file and hits open list_obj.onSelect = function(fileRefList:FileReferenceList){     trace("name: "+fileRefList.fileList[0].name);     trace(file_frl.removeListener(this)); } //add the listener to the FileReference object file_frl.addListener(list_obj); //browse file_frl.browse(); 

Events

onCancel

Availability: FP:8, AS:1.0

Generic Template: Listener.onCancel = function(fileRefList);

Parameter:

  • fileRefList This is a reference to the FileReferenceList object that initiated the dialog window opening.

Description:

This event is triggered when the dialog window is open, and the user chooses Cancel.

Example:

This example will open a dialog box for a user to choose a file; then it listens for the Cancel button:

 import flash.net.FileReferenceList; //the FileReferenceList object var file_frl:FileReferenceList = new FileReferenceList(); //object for listening to for FileReference events var list_obj:Object = new Object(); //the event for when a user selects a file and hits cancel list_obj.onCancel = function(fileRefList:FileReferenceList){     trace("Cancel Hit"); } //add the listener to the FileReference object file_frl.addListener(list_obj); //browse file_frl.browse(); 

onSelect

Availability: FP:8, AS:1.0

Generic Template: Listener.onSelect = function(fileRefList){

Parameter:

  • fileRefList This is a reference to the FileReferenceList object that initiated the dialog window opening.

Description:

This event is triggered when a user selects a file and either clicks Open or double-clicks the file.

Example:

This example will allow the user to select multiple files, and when the user clicks Open, all the properties of each FileReference will be sent to the Ouput panel:

 import flash.net.FileReferenceList; //the listener object var list_obj:Object = new Object(); //when the user has finished selecting the files list_obj.onSelect = function(fileRefList:FileReferenceList){     var list_array = fileRefList.fileList;     var tLength:Number = list_array.length;     var i = 0;     while(i<tLength){         var file = list_array[i];         for(prop in file){             trace(prop + " - " + file[prop]);         }         i++;     } } //FileReferenceList object var file_frl:FileReferenceList = new FileReferenceList(); //add the listener file_frl.addListener(list_obj); //browse file_frl.browse(); 




Macromedia Flash Professional 8 Unleashed
Macromedia Flash Professional 8 Unleashed
ISBN: 0672327619
EAN: 2147483647
Year: 2005
Pages: 319

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net