2008-03-10
flex 上传文件
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" fontSize="12" creationComplete="init()" width="518" height="347">
<mx:Script>
<![CDATA[
import flash.net.FileReference;
import flash.net.URLRequest;
import flash.net.FileFilter;
import flash.net.URLVariables;
import flash.events.ProgressEvent;
import mx.managers.CursorManager;
//
private var file:FileReference;
internal function init():void{
file = new FileReference();
file.addEventListener(Event.SELECT, onSelect);
file.addEventListener(ProgressEvent.PROGRESS, processHandler);
file.addEventListener(DataEvent.UPLOAD_COMPLETE_DATA,uploadDataHandler);
}
internal function doSelect():void{
var imageTypes:FileFilter = new FileFilter("Images (*.jpg, *.jpeg, *.png)", "*.jpg;*.jpeg;*.png");
var allTypes:Array = new Array(imageTypes);
file.browse(allTypes);
}
internal function onSelect(evt:Event):void{
pic_txt.text = file.name;
}
internal function doUpload():void{
var request:URLRequest = new URLRequest("upload.php");
//request.data = new URLVariables();
file.upload(request);
CursorManager.setBusyCursor();
}
internal function processHandler(evt:ProgressEvent):void{
//
//evt.bytesTotal;
}
internal function uploadDataHandler(evt:DataEvent):void{
CursorManager.removeBusyCursor();
img.source = evt.data.toString();
}
]]>
</mx:Script>
<mx:Image id="img" width="377" height="108" x="10" y="59"/>
<mx:TextInput id="pic_txt" width="150" x="109" y="10"/>
<mx:Button label="选择文件" click="doSelect()" x="10" y="10"/>
<mx:Button label="开始上传" click="doUpload()" x="295" y="10"/>
</mx:Application>
原文链接:http://www.fluidea.cn/blog/index.php/2007/12/19/44/
演示地址:http://www.fluidea.cn/book/uploadEx/FlexUpload.html
发表评论
- 浏览: 6586 次
- 性别:

- 来自: 北京

- 详细资料
搜索本博客
最近加入圈子
链接
最新评论
-
【zz】用Spring2.5进行单 ...
建议Service和DAO都采用Spring2.5的注解,不需要在applica ...
-- by chenm_bj -
百度Hi测试邀请
已经发送
-- by ccmv -
百度Hi测试邀请
我想要一个,不知博主可否给一个给我我的百度帐号:gml520谢谢!
-- by gml520 -
flex3 builder 注册码
不客气
-- by ccmv -
flex3 builder 注册码
多谢
-- by lordhong






评论排行榜