HaxeDoc2

(やまだぃちぅ) #1
The code above will display the content of thehellomessage.txtfile that we included earlier
usingwelcomeas the identifier.

8.4.3 Retrieving binary resources


While it’s not recommended to embed large binary files in the application, it still may be useful
to embed binary data. The binary representation of an embedded resource can be accessed using
the static methodgetBytesofhaxe.Resource:

1 class Main {
2 static function main() {
3 var bytes =
4 haxe.Resource.getBytes("welcome");
5 trace(bytes.readString(0, bytes.length));
6 }
7 }


The return type ofgetBytesmethod ishaxe.io.Bytes, which is an object providing access
to individual bytes of the data.

8.4.4 Implementation details


Haxe uses the target platform’s native resource embedding if there is one, otherwise it provides
its own implementation.


  • Flashresources are embedded as ByteArray definitions

  • C#resources are included in the compiled assembly

  • Javaresources are packed in the resulting JAR file

  • C++resources are stored in global byte array constants.

  • JavaScriptresources are serialized in Haxe serialization format and stored in a static field of
    haxe.Resourceclass.

  • Nekoresources are stored as strings in a static field ofhaxe.Resourceclass.


8.5 Runtime Type Information.................................


The Haxe compiler generates runtime type information (RTTI) for classes that are annotated or
extend classes that are annotated with the:rttimetadata. This information is stored as a XML
string in a static field__rttiand can be processed throughhaxe.rtti.XmlParser. The
resulting structure is described inRTTI structure(Section 8.5.1).
Since Haxe 3.2.0

The typehaxe.rtti.Rttihas been introduced in order to simplify working with RTTI.
Retrieving this information is now very easy:

1 @:rtti
2 class Main {
3 var x:String;
4 static function main() {
5 var rtti = haxe.rtti.Rtti.getRtti(Main);

Free download pdf