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