<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Flex Examples &#187; dataTipField</title>
	<atom:link href="http://blog.flexexamples.com/tag/datatipfield/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.flexexamples.com</link>
	<description>Just a bunch of Adobe Flex Examples</description>
	<lastBuildDate>Wed, 26 Jan 2011 18:09:51 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Downloading files in Flex using the FileReference class</title>
		<link>http://blog.flexexamples.com/2007/07/28/downloading-files-in-flex-using-the-filereference-class/</link>
		<comments>http://blog.flexexamples.com/2007/07/28/downloading-files-in-flex-using-the-filereference-class/#comments</comments>
		<pubDate>Sat, 28 Jul 2007 17:20:53 +0000</pubDate>
		<dc:creator>Peter deHaan</dc:creator>
				<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[FileReference]]></category>
		<category><![CDATA[dataTipField]]></category>
		<category><![CDATA[download]]></category>
		<category><![CDATA[showDataTips]]></category>

		<guid isPermaLink="false">http://blog.flexexamples.com/2007/07/28/downloading-files-in-flex-using-the-filereference-class/</guid>
		<description><![CDATA[<p>OK, enough embedding examples, lets take a look at downloading files using Flash Player&#8217;s FileReference class (flash.net.FileReference). This example demonstrates a basic usage of the FileReference class within Flex, allowing users to download a file from the server. This example also shows how you can use data tips in the DataGrid control by setting the [...]]]></description>
			<content:encoded><![CDATA[<p>OK, enough embedding examples, lets take a look at downloading files using Flash Player&#8217;s FileReference class (flash.net.FileReference). This example demonstrates a basic usage of the FileReference class within Flex, allowing users to download a file from the server. This example also shows how you can use data tips in the DataGrid control by setting the data grid column&#8217;s <code>showDataTips</code> property to <code>true</code> and specifying a value for the <code>dataTipField</code> column.</p>
<p>Full code after the jump.</p>
<p><span id="more-35"></span></p>
<p>The following example downloads a ZIP file when the user presses the Button control. You can mouse over the items in the DataGrid control&#8217;s &#8220;Type&#8221; column to see additional event information.</p>
<p class="download"><a href="http://blog.flexexamples.com/wp-content/uploads/FileReference_download_test/bin/srcview/FileReference_download_test.zip">Download source (ZIP, 3K)</a> | <a href="/wp-content/uploads/FileReference_download_test/main.mxml">View MXML</a></p>

<div class="wp_syntax"><div class="code"><pre class="mxml" style="font-family:monospace;"><span style="color: #000000;">&lt;?xml version=<span style="color: #ff0000;">&quot;1.0&quot;</span> encoding=<span style="color: #ff0000;">&quot;utf-8&quot;</span>?<span style="color: #7400FF;">&gt;</span></span>
<span style="color: #000000;"><span style="color: #808080; font-style: italic;">&lt;!-- http://blog.flexexamples.com/2007/07/28/downloading-files-in-flex-using-the-filereference-class/ --&gt;</span></span>
<span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:Application</span> xmlns:mx=<span style="color: #ff0000;">&quot;http://www.adobe.com/2006/mxml&quot;</span></span>
<span style="color: #000000;">        layout=<span style="color: #ff0000;">&quot;vertical&quot;</span></span>
<span style="color: #000000;">        verticalAlign=<span style="color: #ff0000;">&quot;middle&quot;</span></span>
<span style="color: #000000;">        backgroundColor=<span style="color: #ff0000;">&quot;white&quot;</span></span>
<span style="color: #000000;">        creationComplete=<span style="color: #ff0000;">&quot;init();&quot;</span><span style="color: #7400FF;">&gt;</span></span>
&nbsp;
    <span style="color: #339933;">&lt;mx:Script&gt;</span>
<span style="color: #339933;">        &lt;![CDATA[</span>
<span style="color: #339933;">            import mx.controls.Alert;</span>
<span style="color: #339933;">            import mx.collections.ArrayCollection;</span>
<span style="color: #339933;">            import flash.net.FileReference;</span>
&nbsp;
<span style="color: #339933;">            [Bindable]</span>
<span style="color: #339933;">            [Embed('assets/disk.png')]</span>
<span style="color: #339933;">            private var diskIcon:Class;</span>
&nbsp;
<span style="color: #339933;">            [Bindable]</span>
<span style="color: #339933;">            private var arrColl:ArrayCollection;</span>
&nbsp;
<span style="color: #339933;">            /* URL of the file to download. */</span>
<span style="color: #339933;">            private const FILE_URL:String = &quot;http://blog.flexexamples.com/wp-content/uploads/FileReference_download_test/bin/srcview/FileReference_download_test.zip&quot;;</span>
&nbsp;
<span style="color: #339933;">            private var fileRef:FileReference;</span>
<span style="color: #339933;">            private var urlReq:URLRequest;</span>
&nbsp;
<span style="color: #339933;">            private function init():void {</span>
<span style="color: #339933;">                /* Initialize the array collection to an empty collection. */</span>
<span style="color: #339933;">                arrColl = new ArrayCollection();</span>
&nbsp;
<span style="color: #339933;">                /* Set up the URL request to download the file specified by the FILE_URL variable. */</span>
<span style="color: #339933;">                urlReq = new URLRequest(FILE_URL);</span>
&nbsp;
<span style="color: #339933;">                /* Define file reference object and add a bunch of event listeners. */</span>
<span style="color: #339933;">                fileRef = new FileReference();</span>
<span style="color: #339933;">                fileRef.addEventListener(Event.CANCEL, doEvent);</span>
<span style="color: #339933;">                fileRef.addEventListener(Event.COMPLETE, doEvent);</span>
<span style="color: #339933;">                fileRef.addEventListener(Event.OPEN, doEvent);</span>
<span style="color: #339933;">                fileRef.addEventListener(Event.SELECT, doEvent);</span>
<span style="color: #339933;">                fileRef.addEventListener(HTTPStatusEvent.HTTP_STATUS, doEvent);</span>
<span style="color: #339933;">                fileRef.addEventListener(IOErrorEvent.IO_ERROR, doEvent);</span>
<span style="color: #339933;">                fileRef.addEventListener(ProgressEvent.PROGRESS, doEvent);</span>
<span style="color: #339933;">                fileRef.addEventListener(SecurityErrorEvent.SECURITY_ERROR, doEvent);</span>
<span style="color: #339933;">            }</span>
&nbsp;
<span style="color: #339933;">            private function doEvent(evt:Event):void {</span>
<span style="color: #339933;">                /* Create shortcut to the FileReference object. */</span>
<span style="color: #339933;">                var fr:FileReference = evt.currentTarget as FileReference;</span>
&nbsp;
<span style="color: #339933;">                /* Add event order and type to the DataGrid control. */</span>
<span style="color: #339933;">                arrColl.addItem({data:arrColl.length+1, type:evt.type, eventString:evt.toString()});</span>
&nbsp;
<span style="color: #339933;">                try {</span>
<span style="color: #339933;">                    /* Update the Model. */</span>
<span style="color: #339933;">                    fileRefModel.creationDate = fr.creationDate;</span>
<span style="color: #339933;">                    fileRefModel.creator = fr.creator;</span>
<span style="color: #339933;">                    fileRefModel.modificationDate = fr.modificationDate;</span>
<span style="color: #339933;">                    fileRefModel.name = fr.name;</span>
<span style="color: #339933;">                    fileRefModel.size = fr.size;</span>
<span style="color: #339933;">                    fileRefModel.type = fr.type;</span>
<span style="color: #339933;">                    /* Display the Text control. */</span>
<span style="color: #339933;">                    txt.visible = true;</span>
<span style="color: #339933;">                } catch (err:*) {</span>
<span style="color: #339933;">                    /* uh oh, an error of sorts. */</span>
<span style="color: #339933;">                }</span>
<span style="color: #339933;">            }</span>
&nbsp;
<span style="color: #339933;">            private function downloadSourceCodeZip():void {</span>
<span style="color: #339933;">                /* Clear existing array collection. */</span>
<span style="color: #339933;">                arrColl = new ArrayCollection();</span>
<span style="color: #339933;">                /* Hide the Text control. */</span>
<span style="color: #339933;">                txt.visible = false;</span>
<span style="color: #339933;">                /* Begin download. */</span>
<span style="color: #339933;">                fileRef.download(urlReq);</span>
<span style="color: #339933;">            }</span>
&nbsp;
<span style="color: #339933;">            private function showAlert(item:Object):void {</span>
<span style="color: #339933;">                Alert.show(item.eventString, item.type);</span>
<span style="color: #339933;">            }</span>
<span style="color: #339933;">        ]]&gt;</span>
<span style="color: #339933;">    &lt;/mx:Script&gt;</span>
&nbsp;
    <span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:Model</span> id=<span style="color: #ff0000;">&quot;fileRefModel&quot;</span><span style="color: #7400FF;">&gt;</span></span>
        <span style="color: #000000;">&lt;file<span style="color: #7400FF;">&gt;</span></span>
            <span style="color: #000000;">&lt;creationDate<span style="color: #7400FF;">&gt;</span></span>{&quot;&quot;}<span style="color: #000000;">&lt;/creationDate<span style="color: #7400FF;">&gt;</span></span>
            <span style="color: #000000;">&lt;creator<span style="color: #7400FF;">&gt;</span></span>{&quot;&quot;}<span style="color: #000000;">&lt;/creator<span style="color: #7400FF;">&gt;</span></span>
            <span style="color: #000000;">&lt;modificationDate<span style="color: #7400FF;">&gt;</span></span>{&quot;&quot;}<span style="color: #000000;">&lt;/modificationDate<span style="color: #7400FF;">&gt;</span></span>
            <span style="color: #000000;">&lt;name<span style="color: #7400FF;">&gt;</span></span>{&quot;&quot;}<span style="color: #000000;">&lt;/name<span style="color: #7400FF;">&gt;</span></span>
            <span style="color: #000000;">&lt;size<span style="color: #7400FF;">&gt;</span></span>{&quot;&quot;}<span style="color: #000000;">&lt;/size<span style="color: #7400FF;">&gt;</span></span>
            <span style="color: #000000;">&lt;type<span style="color: #7400FF;">&gt;</span></span>{&quot;&quot;}<span style="color: #000000;">&lt;/type<span style="color: #7400FF;">&gt;</span></span>
        <span style="color: #000000;">&lt;/file<span style="color: #7400FF;">&gt;</span></span>
    <span style="color: #000000;"><span style="color: #7400FF;">&lt;/mx:Model</span><span style="color: #7400FF;">&gt;</span></span>
&nbsp;
    <span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:Button</span> id=<span style="color: #ff0000;">&quot;downloadBtn&quot;</span></span>
<span style="color: #000000;">            label=<span style="color: #ff0000;">&quot;Download example source code&quot;</span></span>
<span style="color: #000000;">            icon=<span style="color: #ff0000;">&quot;{diskIcon}&quot;</span></span>
<span style="color: #000000;">            click=<span style="color: #ff0000;">&quot;downloadSourceCodeZip();&quot;</span></span>
<span style="color: #000000;">            toolTip=<span style="color: #ff0000;">&quot;{FILE_URL}&quot;</span></span>
<span style="color: #000000;">            height=<span style="color: #ff0000;">&quot;40&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
&nbsp;
    <span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:DataGrid</span> id=<span style="color: #ff0000;">&quot;debug&quot;</span></span>
<span style="color: #000000;">            dataProvider=<span style="color: #ff0000;">&quot;{arrColl}&quot;</span></span>
<span style="color: #000000;">            width=<span style="color: #ff0000;">&quot;{downloadBtn.width}&quot;</span></span>
<span style="color: #000000;">            rowCount=<span style="color: #ff0000;">&quot;5&quot;</span></span>
<span style="color: #000000;">            rowHeight=<span style="color: #ff0000;">&quot;22&quot;</span></span>
<span style="color: #000000;">            itemClick=<span style="color: #ff0000;">&quot;showAlert(event.currentTarget.selectedItem)&quot;</span><span style="color: #7400FF;">&gt;</span></span>
        <span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:columns</span><span style="color: #7400FF;">&gt;</span></span>
            <span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:DataGridColumn</span> dataField=<span style="color: #ff0000;">&quot;data&quot;</span></span>
<span style="color: #000000;">                    headerText=<span style="color: #ff0000;">&quot;#&quot;</span></span>
<span style="color: #000000;">                    width=<span style="color: #ff0000;">&quot;20&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
            <span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:DataGridColumn</span> dataField=<span style="color: #ff0000;">&quot;type&quot;</span></span>
<span style="color: #000000;">                    headerText=<span style="color: #ff0000;">&quot;Type&quot;</span></span>
<span style="color: #000000;">                    showDataTips=<span style="color: #ff0000;">&quot;true&quot;</span></span>
<span style="color: #000000;">                    dataTipField=<span style="color: #ff0000;">&quot;eventString&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
        <span style="color: #000000;"><span style="color: #7400FF;">&lt;/mx:columns</span><span style="color: #7400FF;">&gt;</span></span>
    <span style="color: #000000;"><span style="color: #7400FF;">&lt;/mx:DataGrid</span><span style="color: #7400FF;">&gt;</span></span>
&nbsp;
    <span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:Text</span> id=<span style="color: #ff0000;">&quot;txt&quot;</span> condenseWhite=<span style="color: #ff0000;">&quot;true&quot;</span> visible=<span style="color: #ff0000;">&quot;false&quot;</span><span style="color: #7400FF;">&gt;</span></span>
        <span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:text</span><span style="color: #7400FF;">&gt;</span></span>
            creationDate: {fileRefModel.creationDate}
            creator: {fileRefModel.creator}
            modificationDate: {fileRefModel.modificationDate}
            name: {fileRefModel.name}
            size: {fileRefModel.size}
            type: {fileRefModel.type}
        <span style="color: #000000;"><span style="color: #7400FF;">&lt;/mx:text</span><span style="color: #7400FF;">&gt;</span></span>
    <span style="color: #000000;"><span style="color: #7400FF;">&lt;/mx:Text</span><span style="color: #7400FF;">&gt;</span></span>
&nbsp;
<span style="color: #000000;"><span style="color: #7400FF;">&lt;/mx:Application</span><span style="color: #7400FF;">&gt;</span></span></pre></div></div>

<p class="information">View source enabled in the following example.</p>
<p><iframe height="400" width="100%" src="http://blog.flexexamples.com/wp-content/uploads/FileReference_download_test/bin/main.html"></iframe></p>
<div class="evernoteSiteMemory"><a href="javascript:" onclick="Evernote.doClip({title: 'Downloading files in Flex using the FileReference class on FlexExamples.com',url: 'http://blog.flexexamples.com/2007/07/28/downloading-files-in-flex-using-the-filereference-class/',contentID: 'post-35',code: 'Pete9667',suggestNotebook: 'FlexExamples',suggestTags: 'dataTipField,download,showDataTips',providerName: 'FlexExamples.com',styling: 'text' });return false" class="evernoteSiteMemoryLink"><img src="http://static.evernote.com/article-clipper-remember.png" class="evernoteSiteMemoryButton" />
				</a>				<div class="evernoteSiteMemoryClear">&nbsp;</div>
</div>]]></content:encoded>
			<wfw:commentRss>http://blog.flexexamples.com/2007/07/28/downloading-files-in-flex-using-the-filereference-class/feed/</wfw:commentRss>
		<slash:comments>57</slash:comments>
		</item>
	</channel>
</rss>

