<?xml version="1.0" encoding="utf-8"?> <!-- http://yecon.blog.hexun.com/31030831_d.html --> <!-- http://www.slsay.com --> <Application name="FileReference_load_test" xmlns="http://ns.adobe.com/mxml/2009" xmlns:mx="library:adobe/flex/halo" xmlns:net="flash.net.*" layout="flex.layout.BasicLayout"> <Script> <!--[CDATA[ import mx.controls.Alert; import mx.utils.ObjectUtil; private function btn_click(evt:MouseEvent):void { var arr:Array = []; arr.push(new FileFilter("Images", ".gif;*.jpeg;*.jpg;*.png")); fileReference.browse(arr); } private function fileReference_select(evt:Event):void { fileReference.load(); } private function fileReference_complete(evt:Event):void { img.source = fileReference.data; Alert.show(ObjectUtil.toString(fileReference)); } ]]--> </Script> <Declarations> <net:FileReference id="fileReference" select="fileReference_select(event);" complete="fileReference_complete(event);" /> </Declarations> <mx:Panel id="panel" layout="absolute" horizontalCenter="0" verticalCenter="0" width="500" height="300"> <mx:Image id="img" verticalCenter="0" horizontalCenter="0" maxWidth="200" maxHeight="200" /> <mx:ControlBar> <mx:Button id="btn" label="Browse and preview..." click="btn_click(event);" /> <mx:Button label="Upload..." enabled="false" /> </mx:ControlBar> </mx:Panel> </Application> 效果如下: