AboutFlex.net

flex,air,flash …

This example shows you the way of open a browse window with a custom filter for files;

This movie requires Flash Player 9

The application:

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
	layout="absolute"
	creationComplete="{init()}"
	>

	<mx:Script>
		<![CDATA[
			import mx.controls.Alert;
			private var imageFilter:FileFilter;
			private var htmlFilter:FileFilter;
			private var fileReference:FileReference;

			private function init():void{

				imageFilter=new FileFilter("Image Files","*.jpg;*.gif;*.png")
				htmlFilter=new FileFilter("HTML Files","*.html")
				fileReference=new FileReference();
				fileReference.addEventListener(Event.SELECT, fileSelectedHandler);

			}

			private function fileSelectedHandler(e:Event):void{
				if( e.target.type.toString()!='.jpg'&&
					e.target.type.toString()!='.png'&&
					e.target.type.toString()!='.gif'&&
					e.target.type.toString()!='.html'){

					Alert.show("Unexpected File Format","Error");	

				}else{

					Alert.show( "Name : "+e.target.name.toString()+"\n"+
						"Type : "+e.target.type.toString()+"\n"+
						"CreationDate : "+e.target.creationDate.toString()+"\n"+
						"Size : "+e.target.size.toString()+"bites \n",
						"File Informations");
				}
			}
			private function browse(filter:FileFilter):void{

				fileReference.browse([filter]);

			}
		]]>
	</mx:Script>
	<mx:Button label="Browse Images Files" click="browse(imageFilter)"  x="10" y="60" width="150"/>
	<mx:Button label="Browse Html Files" click="browse(htmlFilter)"  y="30" x="10" width="150"/>
</mx:Application>

Add A Comment