FLEX 文件上载

<?xml version="1.0" encoding="utf-8"?>

<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" width="294" height="144" usePreloader="true" viewSourceURL="srcview/index.html">
    
<mx:Button x="112" y="23" label="文件上载" click="UploadFile();"/>
    
<mx:ProgressBar id="ProgressBar" labelPlacement="bottom" themeColor="#F20D7A"
                minimum
="0" visible="true" maximum="100" label="当前进度"  
                direction
="right" mode="manual" width="200" x="53" y="67"/>
    
<mx:Label x="147" y="81" text="Label" id="ProgressLabel"/>
<mx:Style>
    ProgressBar 
{
   barColor: #ff00cc;
   paddingLeft: 
0;
   paddingRight: 
3;
   textIndent: 
0;
   letterSpacing: 
0;
   trackHeight: 
14;
   verticalGap: 
0;
   fontSize: 
12;
   fontWeight: normal;
}

</mx:Style>
<mx:Script>
<![CDATA[
        
import flash.events.*;
        
import mx.controls.Alert;
        
import mx.events.*;
        
private var file:FileReference = new FileReference();
        
        
public function UploadFile():void{
            file.addEventListener(Event.SELECT, onSelect);
            file.addEventListener(ProgressEvent.PROGRESS, onProgress);
            file.browse( [ 
new FileFilter("Images""*.jpg;*.gif;*.png"), new FileFilter("Flash Movies""*.swf") ] );
        }

        
        
private function onSelect(e:Event):void {
        Alert.show(
"确认上载?" + file.name + "" + Math.round(file.size/(1024*1024)) + "M?",
                    
"文件上传",
                    Alert.YES
|Alert.NO,
                    
null,
                    doUpload);
        }

        
        
private function onProgress(e:ProgressEvent):void{
            ProgressLabel.text 
= "已上载"+ Math.round(e.bytesLoaded/1024+ "k 共计:"+ Math.round(e.bytesTotal/1024+"k";
            var proc:uint 
= e.bytesLoaded / e.bytesTotal *100;
            ProgressBar.setProgress(proc, 
100);
            ProgressBar.label 
= "当前进度:"+ proc +"%";
        }

        
        
private function doUpload(e:CloseEvent):void{
            
if(e.detail == Alert.YES){
                var request:URLRequest 
= new URLRequest("http://wow.dgoo.net/test/upload.php");
                
try {
                    file.upload(request);
                }

                
catch(e:Error){
                    trace(
"上载错误");
                }

            }

        }

    ]]
>
</mx:Script>
</mx:Application>
 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值