复制代码 代码如下:
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600"
creationComplete="creationCompleteHandler(event)">
<fx:Script>
<![CDATA[
import flash.net.FileReference;
import flash.net.FileFilter;
import flash.events.IOErrorEvent;
import flash.events.Event;
private var fr:FileReference;
private var imageTypes: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]);//打开浏览文件的dialog
}
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 visible="true" autoLoad="true"/>
<mx:Button label="Browse" />
</s:Application>
(编辑:武林网)
新闻热点
疑难解答