`
牧羊人
  • 浏览: 215199 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

flex下载文件

    博客分类:
  • flex
阅读更多
<?xml version="1.0" encoding="utf-8"?> 
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" 
        layout="vertical" 
        verticalAlign="middle" 
        backgroundColor="white" 
        creationComplete="init();">   
  
    <mx:Script> 
        <![CDATA[ 
            import mx.controls.Alert; 
            import mx.collections.ArrayCollection; 
            import flash.net.FileReference;   
  
            [Bindable] 
            [Embed('com/cheping/assets/document.png')] 
            private var diskIcon:Class;   
  
            [Bindable] 
            private var arrColl:ArrayCollection;   
  
            /* URL of the file to download. */ 
            private const FILE_URL:String = "http://192.168.1.9/flex.rar";   
  
            private var fileRef:FileReference; 
            private var urlReq:URLRequest;   
  
            private function init():void { 
                /* Initialize the array collection to an empty collection. */ 
                arrColl = new ArrayCollection();   
  
                /* Set up the URL request to download the file specified by the FILE_URL variable. */ 
                urlReq = new URLRequest(FILE_URL);   
  
                /* Define file reference object and add a bunch of event listeners. */ 
                fileRef = new FileReference(); 
                fileRef.addEventListener(Event.CANCEL, doEvent); 
                fileRef.addEventListener(Event.COMPLETE, doEvent); 
                fileRef.addEventListener(Event.OPEN, doEvent); 
                fileRef.addEventListener(Event.SELECT, doEvent); 
                fileRef.addEventListener(HTTPStatusEvent.HTTP_STATUS, doEvent); 
                fileRef.addEventListener(IOErrorEvent.IO_ERROR, doEvent); 
                fileRef.addEventListener(ProgressEvent.PROGRESS, doEvent); 
                fileRef.addEventListener(SecurityErrorEvent.SECURITY_ERROR, doEvent); 
            }   
  
            private function doEvent(evt:Event):void { 
                /* Create shortcut to the FileReference object. */ 
                var fr:FileReference = evt.currentTarget as FileReference;   
  
                /* Add event order and type to the DataGrid control. */ 
                arrColl.addItem({data:arrColl.length+1, type:evt.type, eventString:evt.toString()});   
  
                try { 
                    /* Update the Model. */ 
                    fileRefModel.creationDate = fr.creationDate; 
                    fileRefModel.creator = fr.creator; 
                    fileRefModel.modificationDate = fr.modificationDate; 
                    fileRefModel.name = fr.name; 
                    fileRefModel.size = fr.size; 
                    fileRefModel.type = fr.type; 
                    /* Display the Text control. */ 
                    txt.visible = true; 
                } catch (err:*) { 
                    /* uh oh, an error of sorts. */ 
                } 
            }   
  
            private function downloadSourceCodeZip():void { 
                /* Clear existing array collection. */ 
                arrColl = new ArrayCollection(); 
                /* Hide the Text control. */ 
                txt.visible = false; 
                /* Begin download. */ 
                fileRef.download(urlReq);
//                fileRef.s 
//                Alert.show( Application.application.url);
                
            }   
  
            private function showAlert(item:Object):void { 
                Alert.show(item.eventString, item.type); 
            } 
        ]]> 
    </mx:Script>   
  
    <mx:Model id="fileRefModel"> 
        <file> 
            <creationDate>{""}</creationDate> 
            <creator>{""}</creator> 
            <modificationDate>{""}</modificationDate> 
            <name>{""}</name> 
            <size>{""}</size> 
            <type>{""}</type> 
        </file> 
    </mx:Model>   
  
    <mx:Button id="downloadBtn" label="Download example source code" icon="{diskIcon}" click="downloadSourceCodeZip()" toolTip="{FILE_URL}" height="40" />   
  
    <mx:DataGrid id="debug" dataProvider="{arrColl}" width="{downloadBtn.width}" rowCount="5" rowHeight="22" itemClick="showAlert(event.currentTarget.selectedItem)"> 
        <mx:columns> 
            <mx:DataGridColumn dataField="data" headerText="#" width="20" /> 
            <mx:DataGridColumn dataField="type" headerText="Type" showDataTips="true" dataTipField="eventString" /> 
        </mx:columns> 
    </mx:DataGrid>   
  
    <mx:Text id="txt" condenseWhite="true" visible="false"> 
        <mx:text> 
        creationDate: {fileRefModel.creationDate} 
        creator: {fileRefModel.creator} 
        modificationDate: {fileRefModel.modificationDate} 
        name: {fileRefModel.name} 
        size: {fileRefModel.size} 
        type: {fileRefModel.type} 
        </mx:text> 
    </mx:Text>   
  
</mx:Application>


分享到:
评论

相关推荐

    Mobile FLEX下载文件

    Mobile FLEX下载文件技术主要涉及Adobe Flex框架在移动设备上的应用,用于从指定的URL下载数据。Flex是一种基于ActionScript和MXML的开源框架,它允许开发者构建富互联网应用程序(RIA),并能运行在多种平台,包括...

    flex文件上传下载,在线以pdf形式浏览文件

    本篇文章将详细讲解如何实现"flex文件上传下载,在线以pdf形式浏览文件"这一功能。 首先,让我们了解一下“flex”在这里的含义。Flex通常指的是Adobe Flex,一个用于构建富互联网应用(RIA)的开源框架。它基于...

    flex 文件上传下载完整代码(修正版)

    在项目开发过程中,经常会遇到文件上传下载的...但在flex中由于安全沙箱的原因flex程序不能直接访问本地文件,但是flex SDK中提供了FileReference和FileReferenceList两个类,可以通过这两个类来实现文件的上传下载。

    Flex 指定文件下载 带进度条

    在Flex编程中,指定文件下载并带有进度条功能是一项常见的需求,这主要涉及到网络I/O操作、事件处理以及用户界面的更新。以下是对这个主题的详细讲解。 首先,Flex是Adobe开发的一种开源富互联网应用程序(RIA)...

    flex文件上传下载

    在 Flex 开发中,文件上传和下载是常见的需求,尤其对于需要处理大量用户上传内容的应用来说,这是一项关键功能。Flex 提供了便捷的方式来进行文件的上传和下载操作,同时可以有效利用服务器资源,提高服务器性能。...

    flex帮助文档--(flex学习文档)

    这个名为"flex帮助文档--(flex学习文档)"的压缩包文件包含了关于Flex的详细学习资料,尤其是针对初学者或者希望深入理解Flex的开发者。 1. **Flex的基本概念** Flex是一个基于MXML和ActionScript的开源框架,...

    flex 官方文档 中文教程

    本教程基于Flex官方文档,旨在为开发者提供中文版的详细学习指南,帮助理解并掌握Flex的核心概念、组件、布局、事件处理以及数据绑定等关键知识点。 1. **Flex简介** Flex是基于ActionScript 3.0和Flash Player或...

    Flex上传文件与下载

    ### Flex与Servlet结合实现文件上传及下载功能 在Flex与Servlet技术结合的背景下,本文将详细介绍如何通过这两种技术实现文件的上传与下载功能。通过分析提供的代码片段,我们可以看到一个典型的Flex应用程序界面...

    Flex中文帮助文档

    本Flex中文帮助文档旨在为初学者提供全面且深入的指导,帮助他们掌握Flex的基本概念、核心组件以及实际开发中的运用。 1. **Flex基础**:Flex是一个强大的开发环境,它提供了丰富的UI组件库和数据绑定机制,让...

    flex中文帮助文档

    这个“flex中文帮助文档”提供了对Flex技术的全面介绍和快速入门指南,旨在帮助开发者更好地理解和使用Flex进行Web应用开发。 一、Flex概述 Flex是一个基于ActionScript编程语言和MXML标记语言的开发框架,它允许...

    Flex多文件上传+md5验证文件是否上传

    2. **Flex文件上传**:Flex应用程序通常使用HTTPService或WebService组件与服务器进行通信。在文件上传过程中,我们可以将FileReference对象的data属性绑定到HTTPService的requestContent,然后调用send方法发起POST...

    flex 中文帮助文档

    flex 中文帮助文档flex 中文帮助文档flex 中文帮助文档flex 中文帮助文档flex 中文帮助文档flex 中文帮助文档flex 中文帮助文档flex 中文帮助文档flex 中文帮助文档flex 中文帮助文档flex 中文帮助文档flex 中文帮助...

    flex在web端上传和下载文件前后台代码

    本示例中,我们将探讨如何使用Flex作为前端,Java作为后端,实现文件的上传和下载功能。Flex是一种基于Adobe Flash Player的富互联网应用(RIA)开发框架,而Java则提供强大的服务器端处理能力。 ### 前端:Flex 1...

    flex4 开发文档

    9. **国际化和本地化**:解释如何使Flex应用支持多语言,包括资源文件的组织和加载。 10. **性能优化**:提供最佳实践和技巧,帮助开发者优化Flex 4应用的性能,减少内存消耗和提高运行速度。 总的来说,"flex4 ...

    flex 文件上传下载完整代码(废弃--代码有错误)

    在本文中,我们将深入探讨基于Flex的文件上传和下载功能,以及如何利用FileReference类来实现这一过程。Flex是Adobe Flash Platform的一部分,它提供了一种强大的方式来构建富互联网应用程序(RIA)。在Flex中,我们...

    Linux下的flex+bison1

    然后,使用Flex命令对.l文件进行处理,命令如下: ``` flex divide.l ``` 这将生成一个lex.yy.c文件,是一个C语言的词法分析器。然后,使用gcc编译并执行此文件,命令如下: ``` gcc lex.yy.c -o divide ``` 这将...

    FLEX开发中文文档

    《FLEX开发中文文档》是一份专为RIA(Rich Internet Applications)开发者编译的资源,主要涵盖了Adobe Flex 2和ActionScript 3的开发技术。这份文档由四部分组成,分别对应四个章节,旨在帮助开发者理解和掌握Flex...

Global site tag (gtag.js) - Google Analytics