随笔 - 25, 文章 - 1, 评论 - 0, 引用 - 0
数据加载中……

[Flex4]-[20100524]-[文件上传]

需要用到的Flex原生态对象

1.FileReferenceList

2.FileReference

3.URLRequest

4.URLVariables


封装对象:
CURL

参考代码:


private var files:FileReferenceList=new FileReferenceList;
files.addEventListener(Event.SELECT, onSelectFiles);
files.browse([
new FileFilter("图片""*.jpg;*.gif;*.png""bmp")]);

protected function onSelectFiles(event:Event):void
{

    
for each (var f:FileReference in files.fileList)
    
{

        var fileItem:Object
=new Object;
        fileItem.file
=f;
        fileItem.name
="NoName";
        fileItem.typeid
=11;
        fileItem.filename
=f.name;
        selectFiles.addItem(fileItem);
    }


}

protected function uploadI_clickHandler(event:MouseEvent):void
{
        
if (selectFiles.length > 0)
        
{

            var item:Object
=selectFiles.removeItemAt(0);

            var curl:CURL
=new CURL;
            curl.url
="UploadImageServlet";
            curl.setData(
"name", item.name);
            curl.setData(
"type", item.typeid);
            curl.setData(
"imagedesc", item.imagedesc);
            var file:FileReference
=item.file as FileReference;
            
if (file != null)
            
{
                file.addEventListener(Event.COMPLETE, onFileUploadComplete);
                file.upload(curl.urlRequest);
            }


        }

        
}

    
protected function onFileUploadComplete(event:Event):void
{
    var f:FileReference
=event.currentTarget as FileReference;
    f.removeEventListener(Event.COMPLETE, onFileUploadComplete);
    uploadI_clickHandler(
null);
}

posted on 2010-05-24 01:28 至尊贝贝 阅读(604) 评论(0)  编辑  收藏 所属分类: FLEX-ALL


只有注册用户登录后才能发表评论。


网站导航: