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

[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);
}

你可能感兴趣的:([Flex4]-[20100524]-[文件上传])