FLASH實現ASP.NET MVC上傳---Flash篇

來源:互聯網
上載者:User

標籤:asp.net   flash   mvc   圖片   上傳   

先看下整體思路,整個上傳,以flash按鈕為入口


建立Flash,添加一個按鈕,並命名為btn


添加類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;//檔案上傳private var file:FileReference=new FileReference();//過濾private var images_filter:FileFilter = new FileFilter("*.jpg, *.jpeg, *.gif, *.png", "*.jpg;*.jpeg;*.gif;*.png");//上傳地址private var uploadURL:URLRequest;//建構函式public function main() {////隱藏預設菜單   var contextmenu:ContextMenu = new ContextMenu;   contextmenu.hideBuiltInItems();//這個參數很重要,後面會提到,重要解決sessionID不一致的問題uid = stage.loaderInfo.parameters.ASPSESSID;jid = stage.loaderInfo.parameters.AUTHID;//提交地址uploadURL =  new URLRequest("/SwfUploadImg/?ASPSESSID=" + uid + "&AUTHID=" + jid);//情境點擊事件btn.addEventListener(MouseEvent.CLICK, clickHandler);//選擇圖片後事件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);}//點擊按鈕事件private function clickHandler(evt:MouseEvent):void{//顯示選擇圖片對話方塊file.browse([images_filter]);}//圖片選擇後事件private function selectedHandler(e:Event):void{ExternalInterface.call("Laugh_UpImg_onSelected",file.name,file.size,file.type);//開始上傳圖片file.upload(uploadURL,"Filedata");}//開始上傳private function openHandler(event:Event):void{ExternalInterface.call("Laugh_UpImg_onStart");}//上傳完成private function uploadCompleteDataHandler(event:DataEvent):void{ExternalInterface.call("Laugh_UpImg_onComplete" , event.data);}//上傳進度private function progressHandler(event:ProgressEvent):void{ExternalInterface.call("Laugh_UpImg_onProgress",event.bytesLoaded,event.bytesTotal);}//上傳錯誤private function ioErrorHandler(event:IOErrorEvent):void{ExternalInterface.call("Laugh_UpImg_onError",event.text);}//上傳許可權錯誤private function securityErrorHandler(event:SecurityErrorEvent):void{ExternalInterface.call("Laugh_UpImg_onSecurityError",event.text);}}}

代碼解釋:

ExternalInterface.call
調用外部JS代碼,第一個參數為JS的函數名,後面一個參數為函數的實參。

根據注釋可以判斷出每個方法的作用。

stage.loaderInfo.parameters.ASPSESSID
接受頁面傳來的參數,用於提交給.net頁面進行許可權的驗證


flash主要作為上傳圖片的主要工具,並且實現了用戶端和服務端的即時資料更新。

FLASH實現ASP.NET MVC上傳---Flash篇

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.