flex AIR读取本地资源

来源:互联网 发布:匿名者黑页源码 编辑:程序博客网 时间:2024/06/05 14:29
<?xml version="1.0" encoding="utf-8"?>
<s:WindowedApplication xmlns:fx="http://ns.adobe.com/mxml/2009" 
   xmlns:s="library://ns.adobe.com/flex/spark" 
   xmlns:mx="library://ns.adobe.com/flex/mx"
   creationComplete="creationCompleteHandler(event)">
<fx:Script>
<![CDATA[
private var file:File;
private var imageTypes:FileFilter;
private function creationCompleteHandler(event:Event):void
{
file = new File();
imageTypes = new FileFilter("Images (*.png, *.cba)",
"*.png; *.cba;")

//增加当打开浏览文件后,用户选择好文件后的Listener
file.addEventListener(Event.SELECT, selectHandler);
}
private function selectHandler(event:Event):void
{
path.text = (event.currentTarget as File).url;
//增加一个文件加载load完成后的listener
file.addEventListener(Event.COMPLETE, onLoadComplete);
file.load(); //加载用户选中文件
}
private function onLoadComplete(event:Event):void
{
imgPhoto.source = file.data;
}
private function browseHandler(event:Event):void 
{
//打开浏览文件的dialog
file.browse([imageTypes]);
}
]]>
</fx:Script>
<mx:Image id="imgPhoto" visible="true" x="58" y="59" width="228" height="226" autoLoad="true"/>
<mx:Button id="btnBrowse" x="342" y="10" label="Browse" click="browseHandler(event)"/>
<s:TextInput id="path" x="10" y="9" width="328"/>
<fx:Declarations>
<!-- 将非可视元素(例如服务、值对象)放在此处 -->
</fx:Declarations>
</s:WindowedApplication>
原创粉丝点击