编程生活

   :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理 ::
  113 随笔 :: 0 文章 :: 18 评论 :: 0 Trackbacks

To embed an arbitrary file, you declare a variable of type Class, and put [Embed] metadata on it, using the MIME type application/octet-stream. For example, you embed a text file like this:

[Bindable]
[Embed(source="Story.txt", mimeType="application/octet-stream")]
private var storyClass:Class;

The compiler autogenerates a subclass of the ByteArrayAsset class and sets your variable to be a reference to this autogenerated class. You can then use this class reference to create instances of the ByteArrayAsset using the new operator, and you can extract information from the byte array using methods of the ByteArray class:

var storyByteArray:ByteArrayAsset = ByteArrayAsset(new storyClass());
var story:String = storyByteArray.readUTFBytes(storyByteArray.length);

posted on 2012-06-27 14:32 wilesun 阅读(243) 评论(0)  编辑  收藏

只有注册用户登录后才能发表评论。


网站导航: