Flex upload local images and browse ahead of the implementation method

Source: Internet
Author: User

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>   

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.