• 文件上传下载小例


    代码
    //文件上传
    package
    {
        
    import flash.net.FileReference;
        
    import flash.events.Event;
        
    import flash.net.URLRequest;

        
    public class UploadExample
        {
            
    public function UploadExample()
            {
                var fileRef:FileReference 
    = new FileReference();
                fileRef.addEventLister(Event.SELECT, selectHandler);
                fileRef.addEventLister(Event.COMPLETE, completeHandler);
                
    try
                {
                    var success:Boolean 
    = fileRef.browse();
                }
                
    catch (error:Rrror)
                {
                    trace(
    "不能浏览文件.");
                }
            }

            function selectHandler(event:Event):
    void
            {
                var request:URLRequest 
    = new URLRequest("");
                
    try
                {
                    fileRef.upload(request);
                }
                
    catch (error:Error)
                {
                    trace(
    "不能上传文件.");
                }
            }

            function completeHandler(event:Event):
    void
            {
                trace(
    "上传文件完成.");
            }
        }
    }
    //文件下载
    package
    {
        
    import flash.display.Sprite;
        
    import flash.net.FileReference;
        
    import flash.net.URLRequest;
        
    import flash.net.URLRequestMethod;
        
    import flash.net.URLVariables;

        
    public class DownloadFileExample extends Sprite
        {
            
    private var fileToDownload:FileReference;

            
    public function DownloadFileExample()
            {
                var request:URLRequest 
    = new URLRequest();
                request.url 
    = "";
                request.method 
    = URLRequestMethod.GET();
                request.data 
    = new URLVariables("id=2");
                fileToDownload 
    = new FileReference();
                
    try
                {
                    fileToDownload.download(request, 
    "file.txt");
                }
                
    catch (error:Error)
                {
                    trace(
    "不能下载数据!");
                }
            }
        }
    }
  • 相关阅读:
    模板-树链剖分
    bzoj2523 聪明的学生
    P1220 关路灯
    BZOJ3572 [Hnoi2014]世界树
    BZOJ4013 [HNOI2015]实验比较
    BZOJ4012 [HNOI2015]开店
    BZOJ4011 [HNOI2015]落忆枫音
    BZOJ4009 [HNOI2015]接水果
    BZOJ4010 [HNOI2015]菜肴制作
    BZOJ4008 [HNOI2015]亚瑟王
  • 原文地址:https://www.cnblogs.com/sevenyuan/p/1614281.html
Copyright © 2020-2023  润新知