Flash implementation of ASP. NET MVC upload---Flash article

Source: Internet
Author: User

First look at the whole idea, the whole upload, flash button for the entrance


Create Flash, add a button, and name it BTN


Add Class Main.as

Package {Import Flash.display.*;import flash.events.*;import flash.net.*;import Flash.ui.*;import Flash.external.externalinterface;public class Main extends Sprite {public var btn:simplebutton;private var uid:string; private Var jid:string;private var sn:string;//file upload private var file:filereference=new filereference ();//Filter private Var Images_filter:filefilter = new FileFilter ("*.jpg, *.jpeg, *.gif, *.png", "*.jpg;*.jpeg;*.gif;*.png");//upload address private Var   uploadurl:urlrequest;//constructor Public Function main () {////hides default menu var contextmenu:contextmenu = new ContextMenu; Contextmenu.hidebuiltinitems ();//This parameter is very important, will be mentioned later, the important solution sessionid inconsistent problem uid = Stage.loaderInfo.parameters.ASPSESSID; Jid = stage.loaderinfo.parameters.authid;//Submit Address Uploadurl = new URLRequest ("/swfuploadimg/? Aspsessid= "+ uid +" &authid= "+ Jid);//Scene Click event Btn.addeventlistener (Mouseevent.click, ClickHandler);//   Select Post-image event File.addeventlistener (Event.select, Selectedhandler); File.addeventlistener (Event.open, OpenHandler); File.addeventlistEner (progressevent.progress, Progresshandler);   File.addeventlistener (Ioerrorevent.io_error, Ioerrorhandler); File.addeventlistener (Securityerrorevent.security_error, Securityerrorhandler); File.addeventlistener ( Dataevent.upload_complete_data,uploadcompletedatahandler);} Click the button event Private function ClickHandler (evt:mouseevent): void{//Display Select Picture dialog File.browse ([Images_filter]);} After the picture selection event Private Function Selectedhandler (e:event): Void{externalinterface.call ("laugh_upimg_onselected", File.name,file.size,file.type);//Start uploading pictures file.upload (Uploadurl, "Filedata");} Start uploading Private Function Openhandler (event:event): Void{externalinterface.call ("Laugh_upimg_onstart");} Upload Complete Private Function Uploadcompletedatahandler (event:dataevent): Void{externalinterface.call ("Laugh_upimg_ OnComplete ", event.data);} Upload Progress Private Function Progresshandler (event:progressevent): Void{externalinterface.call ("Laugh_upimg_onprogress" , event.bytesloaded,event.bytestotal);} Upload Error Private Function Ioerrorhandler (event:ioerrorevent): Void{exTernalinterface.call ("Laugh_upimg_onerror", Event.text);} Upload permission error private function Securityerrorhandler (event:securityerrorevent): Void{externalinterface.call ("laugh_upimg _onsecurityerror ", Event.text);}}}

Code Explanation:

Externalinterface.call
Call the external JS code, the first parameter is the function name JS, the next parameter is the argument of the function.

The action of each method can be judged according to the annotations.

Stage.loaderInfo.parameters.ASPSESSID
Accept the parameters from the page for validation of permissions submitted to the. NET page


Flash is mainly used as the main tool for uploading images, and it realizes real-time data update on client and server.

Flash implementation of ASP. NET MVC upload---Flash article

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.