<?
XMl version="1.0" encoding="utf-8"?>
<s:Application x
MLns:fx="http://ns.adobe
.COM/mxml/2009"
xmlns:s="li
brary://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minH
eight="600"
creation
complete="creationCompleteHandler(event)">
<fx:Script>
<![CDATA[
import flash.net.FileReference;
import flash.net.FileFilter;
import flash.events.IOErro
revent;
import flash.events.Event;
PRivate
VAR fr:FileReference;
private var imageTy
PEs:FileFilter;
private function creationCompleteHandler(event:Event):void {
fr = new FileReference();
imageTypes = new FileFilter("Images (*.
jpg, *.jpeg, *.png, *.gif)","*.jpg; *.jpeg; *.png; *.gif;")
fr.addEventListener(Event.SELECT, selectHandler);//增加当打开浏览文件后,用户选择好文件后的Listener
}
private function browseHandler(event:Event):void {
fr.browse([imageTypes]);//打开浏览文件的dia
LOG }
private function selectHandler(event:Event):void {
fr.addEventListener(Event.COMPLETE, onLoadComplete);//增加一个文件加载load完成后的listener
fr.load(); //加载用户选中文件
}
private function onLoadComplete(e:Event):void
{
imgPhoto.source = fr.data;
}
]]>
</fx:Script>
<s:layout>
<s:BasicLayout/>
</s:layout>
<fx:Declarations>
<!-- 将非可视元素(例如服务、值对象)放在此处 -->
</fx:Declarations>
<
;mx:Image id="imgPhoto" visible="true" autoLoad="true" width="1000" height="500"/>
<mx:Button id="
BTnBrowse" label="Browse" click="browseHandler(event)" />
</s:Application>