做了几天,都没做出来。
这次非常谢谢 杜增强 ,
让我又长知识了。
下面源码:
- <?xml version="1.0" encoding="utf-8"?>
- <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" fontSize="12" creationComplete="init()">
- <mx:Script>
- <![CDATA[
- import mx.utils.*;
- import flash.net.*;
- private var fileReference:FileReference=new FileReference();
- private var byteArray:ByteArray;
- private var bitmapData:BitmapData;
- private var loader:Loader=new Loader();
- private function init():void
- {
- fileReference.addEventListener(Event.COMPLETE,fileReferenceCompleteHandler);
- }
- private function fileReferenceCompleteHandler(e:Event):void
- {
- byteArray = fileReference.data;
- loader.contentLoaderInfo.addEventListener(Event.COMPLETE,loaderCompleteHandler);
- loader.loadBytes(byteArray);
- }
- private function loaderCompleteHandler(e:Event):void
- {
- var bitmap:Bitmap = Bitmap(loader.content);
- bitmapData = bitmap.bitmapData;
- img.source = bitmap;
- }
- private function fileReferenceSelectHandler(e:Event):void
- {
- fileReference.load();
- }
- private function btnClick():void
- {
- fileReference.browse();
- fileReference.addEventListener(Event.SELECT,fileReferenceSelectHandler);
- }
- ]]>
- </mx:Script>
- <mx:Panel width="456" height="345" horizontalCenter="0" verticalGap="0" horizontalAlign="center" verticalAlign="middle">
- <mx:Image id="img" width="263" height="234"/>
- <mx:Button label="选择..." click="btnClick()"/>
- </mx:Panel>
- </mx:Application>