API Examples

This page is used to accumulate code examples for various pieces of the Haxe API. It will most likely be temporary. The intent is for these examples to be moved over to the main API docs eventually.

The examples themselves use the ActionScript 3.0 Reference as inspiration. Each example should be a complete program that the reader can copy, paste and compile easily.

Reflect

Fields

class FieldReflection {
    public static function main() {
        var rectangle:Dynamic = {
            width: 100,
            height: 200
        };

        // Accessing fields dynamically
        trace(Reflect.field(rectangle, "width"));  // Traces '100'
        trace(Reflect.field(rectangle, "height")); // Traces '200'

        // Looping over all fields in an object
        var fields:Array<String> = Reflect.fields(rectangle);
        for (fieldName in fields) {
            trace(fieldName);
        }

        // TODO: more field manipulation
    }
}

Functions

TODO

Type

TODO

version #15360, modified 2012-08-16 19:22:06 by alexmiller