我的目标是将嵌入资源写入文件
[Embed(source="Embed/viewer.js", mimeType="application/octet-stream")]
private var viewer_js:Class;
[Embed(source="Embed/viewer2.js", mimeType="application/octet-stream")]
private var viewer2_js:Class;
private function writeAssetToFile(embed:Class, targetFileName:String):void {
var file:File = File.desktopDirectory.resolvePath(targetFileName);
var fs:FileStream = new FileStream();
fs.open(file, FileMode.WRITE);
fs.writeBytes(embed as ByteArray); // error here
fs.close();
}
例如:
writeAssetToFile(viewer_js,"viewer.js");
fs.writeBytes(嵌入为ByteArray);是造成问题的一条线。
问候
答案 0 :(得分:2)
你只需编写一个类的实例,如下所示:
private function writeAssetToFile(embed:Class, targetFileName:String):void {
var file:File = File.desktopDirectory.resolvePath(targetFileName);
var fs:FileStream = new FileStream();
fs.open(file, FileMode.WRITE);
fs.writeBytes(new embed() as ByteArray); // here, should fix
fs.close();
}
诀窍是,嵌入application/octet-stream
的任何内容都被实例化为ByteArray
后代,因此您不需要再做任何事情。