上文講到
flex
利用blazeds
來上傳檔案,本文則封裝了乙個元件用於檔案的上傳導入,其主要功能有:
1)檔案的選擇;
2)檔案型別的限定,比如只能選擇
txt檔案,檔案等;
3)檔案上傳,利用
blazeds;4
)檔案匯入,利用
blazeds;5
)上傳、匯入的事件分發;
1、檔案上傳元件核心**
<?xml version="1.0" encoding="utf-8"?>
xmlns:s="library:"
xmlns:mx="library:" width="300" height="28" creationcomplete="init()">
fault="ro_faulthandler(event)"/>
[event(name="result", type="event.fileimportevent")]
[event(name="fault", type=" event.fileimportevent")]
import mx.controls.alert;
import mx.messaging.channels.streamingamfchannel;
import mx.rpc.events.faultevent;
import mx.rpc.events.resultevent;
import mx.rpc.remoting.remoteobject;
private var file:filereference = new filereference();
private var _filefilter:array=;
private var ro:object;
protected function init():void
private function completehandler(event:event):void
private function selecthandler(event:event):void
/***
設定檔案過濾,開啟檔案選擇框時刻選擇哪些型別的檔案
讀取和設定檔案最大尺寸,單位為
byte,1k = 1024byte,
預設值為
20m*/
public function get maxfilesize():number
public function set maxfilesize(size:number):void
private function checkfile():boolean
if(file.size>_maxfilesize)
超出最大尺寸
.",file.size/1000,_maxfilesize/1000));
blnresult = false;
}if(file.data==null)
return blnresult;
} protected function btnbrowse_clickhandler(event:mouseevent):void
protected function b***elete_clickhandler(event:mouseevent):void
protected function ro_resulthandler(event:resultevent):void
protected function ro_faulthandler(event:faultevent):void
public function importfile(headers:array):boolean
return issuccess;
} public function uploadfile():boolean
return issuccess;
}]]>
選擇檔案
" click="btnbrowse_clickhandler(event)"
paddingleft="3" paddingright="3" bottom="3" icon = "@embed('assets/tool_folder_explore.png')"/>
labelplacement="right" click="b***elete_clickhandler(event)" paddingleft="3" paddingright="3" tooltip="
取消檔案選擇
"/>2、
fileimportevent事件
packageevent
// publicfunctiongetresult():object
publicfunctionsetresult(value:object):void//
publicfunctiongetfault():fault
publicfunctionsetfault(value:fault):void
} }
3、示例
<?xml version="1.0" encoding="utf-8"?>
" xmlns:s="
library:"
xmlns:mx="
library:
" minwidth="
800" minheight="
600" creationcomplete="init()" width="
370" height="
180"
xmlns:fileupload="
fileupload.*
">
importmx.controls.alert;
importevent.fileimportevent;
protectedfunctioninit():void
protectedfunctionbtnupload_clickhandler(event:mouseevent):void
protectedfunctionimporter_resulthandler(event:fileimportevent):void
protectedfunctionimporter_faulthandler(event:fileimportevent):void
protectedfunctionbtnimport_clickhandler(event:mouseevent):void
]]>
id="
importer
" filefilter="
*.txt"
result="importer_resulthandler(event)" fault="importer_faulthandler(event)"
/>
id="
btnupload
" click="btnupload_clickhandler(event)" label="
上傳" x="
89" y="88"
/>
id="
btnimport
" click="btnimport_clickhandler(event)" label="
匯入" x="
182" y="88"
/>
Flex 檔案上傳導入元件
上文講到flex 利用blazeds 1 檔案的選擇 2 檔案型別的限定,比如只能選擇txt 檔案,檔案等 3 檔案上傳,利用blazeds 4 檔案匯入,利用blazeds 5 上傳 匯入的事件分發 1 檔案上傳元件核心 xmlns s library xmlns mx library width...
Flex 檔案上傳導入元件
flex 檔案上傳導入元件 2010年09月13日 1 檔案的選擇 2 檔案型別的限定,比如只能選擇txt檔案,檔案等 3 檔案上傳,利用blazeds 4 檔案匯入,利用blazeds 5 上傳 匯入的事件分發 1 檔案上傳元件核心 flex spark xmlns mx library widt...
Flex 檔案上傳導入元件
1 檔案的選擇 2 檔案型別的限定,比如只能選擇txt檔案,檔案等 3 檔案上傳,利用blazeds 4 檔案匯入,利用blazeds 5 上傳 匯入的事件分發 1 檔案上傳元件核心 flex spark xmlns mx library width 300 height 28 creationco...