Flex--读写本地文件 in Flash Player 10

     Flash Player 10中的一个新的特点就是更新了ActionScript FileReference APIs,新的FileReference允许Flash能够直接读写用户系统的数据。

     在Flash Player 10之前,为了能够读写用户的本地文件,Flash首先不得不先把它反弹回sever端,然后再从server端加载它,之后才可以访问它,这样不仅编程实现起来麻烦,而且还增加了应用的延迟和资源的使用。

     The new functionality is achieved through the addition of two new APIs on the FileReference class:

FileReference.load() : Loads data from a file selected by the user.
FileReference.save() : Saves data to a file location selected by the user.


需要记住以下几点:
  ·The load() and save() APIs can only be called in response to user interaction (such as a button click).
  ·The locations of the loaded and save files are not exposed to ActionScript.
  ·The APIs are asynchronous (异步的)(non-blocking).

 


Below are two examples that show how to use the APIs. The examples use Flex for the UI, but the ActionScript is the same regardless of whether you are using Flex or not.

 

Read a file from the users system: 

 

Write a file to the users system:

 

 

In addition to the events shown in the examples above, the following events are also broadcast by the APIS:

ProgressEvent.PROGRESS : Gives progress on the reading or writing of the file
Event.OPEN : Broadcast when the file is opened for reading or writing.
 While it will also be possible to use these APIs in Adobe AIR, in general, you will want to use the AIR File APIs as they provide more functionality and flexibility.

 

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值