使用Embed标签可以将图片绑定到swf中并显示,那么我们如何将XML或者文本文件也同样绑定到swf中显示或使用呢?同样也是使用Embed标签,经过查阅官方文档 ,发现有个mimeType属性,该属性配置如下:
application/octet-stream
application/x-font
application/x-font-truetype
application/x-shockwave-flash
audio/mpeg
image/gif
image/jpeg
image/png
image/svg
image/svg-xml
也就是说,可以将绑定的内容转换成“二进制数据”。
<fx:Script> <!--[CDATA[ [Embed(source="/assets/sample.txt", mimeType="application/octet-stream")] public var txtCls:Class; [Embed(source="/assets/sample.xml", mimeType="application/octet-stream")] public var xmlCls:Class; /** * init * * @return void * **/ private function init():void { //文本文件 var byteDataTxt:ByteArray = new txtCls(); var str:String = byteDataTxt.readUTFBytes(byteDataTxt.bytesAvailable); trace(str); //XML var byteDataXml:ByteArray = new xmlCls(); var xml:XML = XML(byteDataXml.readUTFBytes(byteDataXml.bytesAvailable)); trace(xml.toXMLString()); } ]]--> </fx:Script>