文件下载例子

接下来的例子演示了Flex中如何利用Flash播放器的FileReference类(flash.net.FileReference),从服务器端下载文件到本地。在这个例子中,同样还可以了解DataGrid中通过设置showDataTips属性为True并且在dataTipField列中指定一个值。

<?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('assets/disk.png')]
private var diskIcon:Class;

[Bindable]
private var arrColl:ArrayCollection;

/* URL of the file to download. */
private const FILE_URL:String = "http://blog.minidx.com/ext/downloading-files-in-flex-using-the-filereference-class/srcview/main.zip";

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

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>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
### 回答1: 首先,AD和PADS都是EDA(电子设计自动化)软件,用于电路设计和PCB(印刷电路板)布局。在这两个软件中,ASC文件是一种通用的文件格式,用于保存电路数据和设计参数。 要下载一个AD到PADS的ASC文件的例子,可以按照以下步骤进行操作: 1. 打开互联网浏览器,访问电子设计网站或电子设计社区。例如,在电子设计社区EDABOARD或EDA中国,你可以找到一些用户上传的示例设计文件和资源。 2. 在该网站的搜索栏中输入关键字"AD to PADS ASC file example",然后点击搜索按钮。 3. 在搜索结果中,将会出现一些与你所搜索的关键字相关的帖子和文章。浏览这些帖子和文章,寻找可能下载示例文件的链接或附件。 4. 点击含有ASC文件示例的链接或附件,然后选择将其下载到你的计算机上。通常,下载文件时会出现保存文件对话框,你可以选择一个适当的文件夹来保存ASC文件。 5. 下载完成后,你可以使用AD或PADS软件打开这个ASC文件,仔细查看设计数据和参数。你还可以将其作为参考来学习和了解AD和PADS之间的电路转换过程。 需要注意的是,示例文件可能是由其他用户上传的,因此请确保通过下载链接或附件的方式来获取它们,以确保安全和合法性。 总之,通过在电子设计社区或设计网站上搜索,你应该能够找到一些可以下载的AD到PADS的ASC文件的示例。这些示例可以作为学习和参考的资源,帮助你更好地理解和应用AD和PADS软件。 ### 回答2: 要下载ad to pads asc文件例子,您可以按照以下步骤进行: 1. 打开您的互联网浏览器,例如Chrome,Firefox或Edge。 2. 在搜索栏中输入“ad to pads asc文件例子下载”并按下Enter键。 3. 阅读搜索结果,选择一个可靠的网站,例如官方软件或技术论坛。 4. 点击选定的网站链接,进入该网站的主页。 5. 在主页上寻找与您需要的文件相关的搜索栏或下载部分。 6. 输入“ad to pads asc文件例子”或类似的关键词,并点击搜索按钮。 7. 在搜索结果中,找到符合您需求的文件,通常会显示文件名称、大小和下载链接。 8. 点击下载链接,等待文件下载完成。 9. 一旦下载完成,您可以在浏览器的下载文件夹中找到该文件,通常默认保存到“Downloads”文件夹中。 10. 使用合适的软件打开下载的ad to pads asc文件例子,例如使用PADS软件或相关电路设计工具。 请注意,为了确保您从可信任的来源下载文件,请始终注意下载文件的来源和网站的可信度。当下载和使用任何文件时,您应该保持计算机的安全性,并确保文件没有潜在的病毒或恶意软件。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值