专注收集记录技术开发学习笔记、技术难点、解决方案
网站信息搜索 >> 请输入关键词:
您当前的位置: 首页 > Flex

FileReference 与URLRequest 上传图片后,怎么获得服务器端返回值

发布时间:2011-06-27 19:27:51 文章来源:www.iduyao.cn 采编人员:星星草
FileReference 与URLRequest 上传图片后,如何获得服务器端返回值!
以下是FLEX 代码:

a.mxml

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="init();">
<mx:Script>
<![CDATA[
import mx.controls.Alert;
import mx.managers.CursorManager;

private var urlRequset:URLRequest;
       private var file:FileReference = new FileReference();//实例化一个文件类件
       private var serverSide:String = "http://localhost/photo/upfile33.php";//指明后台处理的文件
         
private function init():void{
    localChoose.addEventListener(MouseEvent.CLICK,doSelect);
    file.addEventListener(Event.SELECT,onSelect);
   resetBtn.addEventListener(MouseEvent.CLICK,doReset);
   submitBtn.addEventListener(MouseEvent.CLICK,doUpload);
     
}
public function uploadCompleteHandler(event:Event):void{//上传成功
    localPath.text = event.target.name+"文件上传成功!";
    Alert.show(localPath.text,"提示");
}

public function doSelect(evt:Event):void{//选取文件
       file.browse();
}
public function onSelect(evt:Event):void{//选取文件完成
    localPath.text=file.name;
}
public function doReset(evt:Event):void{//重置
    localPath.text='';
}
public function doUpload(event:Event):void{//开始上传
if(localPath.text==''){
    Alert.okLabel = "确 定";
    Alert.show("请选择要上传的文件!","警告");
}else{
    var request:URLRequest=new URLRequest(serverSide);
    file.addEventListener(Event.COMPLETE, uploadCompleteHandler);
    file.addEventListener(ProgressEvent.PROGRESS,processHandler);
    localPath.text = "正在上传 " + file.name;
    CursorManager.setBusyCursor();
    file.upload(request);
}

}
public function processHandler(evt:ProgressEvent):void{//上传进度
        if(evt.bytesLoaded == evt.bytesTotal)
        {
        CursorManager.removeBusyCursor();
        }else
        {
           var proc:uint=evt.bytesLoaded/evt.bytesTotal*100;
           localPath.text="已上传:"+proc;
        }
}
]]>
</mx:Script>
<mx:Panel x="10" y="10" width="421" height="184" layout="absolute" title="FLEX上传工具DEMO" fontSize="12" fontWeight="bold">
<mx:Label x="37" y="31" text="上传文件:"/>
<mx:TextInput   id="localPath" x="107" y="29" width="179.5" editable="false"/>
<mx:Button id="localChoose" x="312" y="29" label="选择"/>
<mx:Button id="submitBtn" x="107" y="79" label="开始上传" />
<mx:Button id="resetBtn" x="234.5" y="79" label="重填"/>
</mx:Panel>
</mx:Application>

友情提示:
信息收集于互联网,如果您发现错误或造成侵权,请及时通知本站更正或删除,具体联系方式见页面底部联系我们,谢谢。

其他相似内容:

热门推荐: