3

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?

Gama11
  • 31,714
  • 9
  • 78
  • 100
RCIX
  • 38,647
  • 50
  • 150
  • 207

4 Answers4

11

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));
stroncium
  • 1,430
  • 9
  • 8
  • 1
    Why for God sake should I enter width and height of the image? This is terrible practice! If I have a hundred of images I would waste tons of time finding their sizes and entering them as magical numbers. I hope Haxe's developers will overthink this and make something similar to flash's [embed] tag, which was not perfect but at least not such a headache. – momijigari Aug 25 '14 at 07:08
  • If you specify 0, 0 for the width and height it should be fine. When I tried it with anything other than 0 it seemed to ignore the values specified anyway. – Rich Dec 23 '14 at 20:04
  • And actually it's exactly the way it behaves in flash under the hood. swf container integrates with avm bytecode in this predefined way. – stroncium Dec 24 '14 at 06:44
4

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

You may refer to the doc.

Gama11
  • 31,714
  • 9
  • 78
  • 100
Andy Li
  • 5,894
  • 6
  • 37
  • 47
2

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"));
0

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.

moveaway00
  • 918
  • 1
  • 5
  • 13
  • So the `@myxml` portion is what identifies the file with an alias when used in the actual Haxe code (with Resource.getString) ? – chamberlainpi Nov 12 '14 at 16:36