Haxe — Embed files like in ActionScript?

主宰稳场 提交于 2019-12-23 21:07:42

问题


In ActionScript, you can do something like this:

[Embed(source = "src/myfile.xml", mimeType = "application/octet-stream")]
private var xml : Class;

and it will embed your file to be used in code. How can i do something similar in Haxe?


回答1:


Haxe allows you to provide external resources info for embedding in hxml.

You may refer to the doc.




回答2:


Things have changed since the time the question was asked. With a modern version of haxe one can do:

@:bitmap("test.png") class TestBMD extends BitmapData {}
var bm = new Bitmap(new TestBMD(100,100));



回答3:


If specifying width/height annoys you, and if you don't mind not using the @:bitmap metatag, you could do:

import openfl.Assets;
...
var bm = new Bitmap(Assets.getBitmapData("test.png"));



回答4:


XML is easy to use haxe to get. Add -resource myfile.xml@myxml. Then, in your code, to get the xml string, use haxe.Resource.getString("myxml"). You can then parse this string to xml.



来源:https://stackoverflow.com/questions/3664148/haxe-embed-files-like-in-actionscript

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!