Flex中通过给flash.net包自定一个命名空间在MXML中定义FileReference对象的例子
By Minidxer | August 28, 2008
在前面的Flex中利用FileReference类下载文件的例子中,我们了解了FileReference的基本用法。接下来的例子演示了Flex中通过给flash.net包自定一个命名空间,在MXML中定义FileReference对象。
让我们先来看一下Demo(可以右键View Source或点击这里察看源代码):
下面是完整代码(或点击这里察看):
Download: main.mxml
- <?xml version="1.0" encoding="utf-8"?>
- <!-- http://blog.flexexamples.com/2008/08/25/creating-a-filereference-object-using-mxml-in-flex/ -->
- <mx:Application name="FileReference_download_test_2"
- xmlns:mx="http://www.adobe.com/2006/mxml"
- xmlns:net="flash.net.*"
- layout="vertical"
- verticalAlign="middle"
- backgroundColor="white">
- <mx:Script>
- <![CDATA[
- import mx.controls.Alert;
- private const DOWNLOAD_URL:String = "http://blog.flexexamples.com/wp-content/uploads/FileReference_download_test_2/bin/srcview/FileReference_download_test_2.zip";
- private function btn_click(evt:MouseEvent):void {
- var urlReq:URLRequest = new URLRequest(DOWNLOAD_URL);
- fileReference.download(urlReq);
- }
- private function onEvent(evt:Event):void {
- Alert.show(evt.toString(), evt.type);
- }
- ]]>
- </mx:Script>
- <net:FileReference id="fileReference"
- complete="onEvent(event);"
- cancel="onEvent(event);"
- httpStatus="onEvent(event);"
- ioError="onEvent(event);" />
- <mx:Button id="btn"
- label="Download source"
- click="btn_click(event);" />
- </mx:Application>
代码:Peter deHaan 翻译/整理/编译:中文Flex例子
Topics:
Flex |
No Comments » |
249 views
Tags: download, FileReference, MXML