The
personality Avatar eventually needs to be uploaded to the server's filesystem, but the program wants to have a preview directly after the user chooses, for this problem, there is a rough implementation, I hope to help you.
Often design a feature such as changing the Avatar, which eventually needs to be uploaded to the server's filesystem, but the program wants to have a preview directly after the user chooses, and then the user uploads. This feature is technically necessary to read local files. In the Flash player10, there is a class Filereference class can implement this function, and the implementation of the file read the interface is the load () function, note that: A, this function can only be used in UI operations, such as the user presses the button. B, the loaded local files can not be used in the as in C, this interface is an asynchronous process, it is not immediately loaded in, need to add listener to operate. Below is the reference code code as follows: <?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=" 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 (); &nBsp Imagetypes = new FileFilter ("Images (*.jpg, *.jpeg, *.png, *.gif)", "*.jpg; *.jpeg; *.png;") Fr.addeventlistener (Event.select, Selecthandler)//increase when the browse file is opened, the user chooses a good file listener } Private function Browsehandler (event:event): void { fr.browse ([imagetypes]);//Open browse file dialog } Private Function Selecthandler (event:event): void { Fr.addeventlistener (event.complete, onloadcomplete); Add a file load after loading completes the listener fr.load (); Load user checked files } Private Function Onloadcomplete (e:event):void { imgphoto.source = fr.data;& nbsp } ]]> </fx:Script> <s:layout> <s:BasicLayout/> </s: layout> <fx:Declarations> <!--to place non-visual elements (such as services, value objects) here--> </fx:Declarations> <mx:image id= "Imgphoto" visible= "true" autoload= "true" width= "1000" height= "$"/> <mx:button ID = "Btnbrowse" label= "Browse" click= "Browsehandler (EVent) "/> </s:Application>