<!--?注释掉的代码是原创,引用自http://bbs.9ria.com/thread-85208-1-1.html ,没有注释的代码是自己改写的-->
?
<!--
?<?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"
?title="AIR遍历文件夹" creationComplete="windowedapplication1_creationCompleteHandler(event)">
?<fx:Script>
?<![CDATA[
?import mx.events.FlexEvent;
?
?private var file:File;
?protected function windowedapplication1_creationCompleteHandler(event:FlexEvent):void
?{
?this.removeEventListener(FlexEvent.CREATION_COMPLETE,windowedapplication1_creationCompleteHandler);
?file = new File();
?file.addEventListener(Event.SELECT,file_selectHandler);
?}
?//File的选择事件
?protected function file_selectHandler(event:Event):void
?{
?var arr:Array = file.getDirectoryListing();
?dg.dataProvider = arr;
?this.status = file.nativePath;
?}
?//单击按钮
?protected function btn_clickHandler(event:MouseEvent):void
?{
?file.browseForDirectory("请选择一个文件夹");
?}
?
?]]>
?</fx:Script>
?<fx:Declarations>
?
?</fx:Declarations>
?<s:Button id="btn" label="打开"? click="btn_clickHandler(event)"/>
?<mx:DataGrid id="dg" width="100%" height="100%" y="30">
??<mx:columns>
???<mx:DataGridColumn headerText="文件名" dataField="name"/>
???<mx:DataGridColumn headerText="创建日期" dataField="creationDate"/>
???<mx:DataGridColumn headerText="修改日期" dataField="modificationDate"/>
???<mx:DataGridColumn headerText="文件夹" dataField="isDirectory"/>
???<mx:DataGridColumn headerText="大小" dataField="size"/>
???<mx:DataGridColumn headerText="类型" dataField="type"/>
??</mx:columns>
?</mx:DataGrid>
?</s:WindowedApplication>
-->
<?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" ??????? title="AIR遍历文件夹" > ?<fx:Script> ??<![CDATA[ ???import mx.controls.Alert; ???//import mx.events.FlexEvent; ???private var file:File; ???//File的选择事件 ???protected function file_selectHandler(event:Event):void ???{ ????var arr:Array = file.getDirectoryListing(); ????for(var i:int = 0 ; i < arr.length ; i ++){ ?????Alert.show(arr[i].name) ; ????} ???} ???//单击按钮 ???protected function btn_clickHandler(event:MouseEvent):void ???{ ????file = new File(); ????file.addEventListener(Event.SELECT,file_selectHandler); ????file.browseForDirectory("请选择一个文件夹"); ???} ??? ??]]> ?</fx:Script> ?<fx:Declarations> ??<!-- 将非可视元素(例如服务、值对象)放在此处 --> ?</fx:Declarations> ?<s:Button id="btn" label="打开"? click="btn_clickHandler(event)"/> ?<mx:TabNavigator> ?? ?</mx:TabNavigator> </s:WindowedApplication>