Question

I have this actionScript3 Code I'm porting to haxe.

public static const DATA_COMPLETE_LEVELS : String   = "save_game_data_complete_levels";
private var _completedLevelKeys:Vector.<String>;


public function get completedLevelKeys():Vector.<String> {
    if (this.data[DATA_COMPLETE_LEVELS])
        return (Vector.<String>)(this.data[DATA_COMPLETE_LEVELS]);
    return null;

}           
public function set completedLevelKeys(value:Vector.<String>):void {
    if(value)
        this.data[DATA_COMPLETE_LEVELS] = (Vector.<String>)(value);
}

I'm just getting my hands dirty with haxe, andI got a bit confused with Reflect

What is the equivalent code in Haxe ?

Was it helpful?

Solution

This should work:

public static inline var DATA_COMPLETE_LEVELS = "save_game_data_complete_levels";

public var completedLevelKeys(get, set) : Vector<String>;

function get_completedLevelKeys() : Vector<String>
    return Reflect.field(this.data, DATA_COMPLETE_LEVELS);

function set_completedLevelKeys(values : Vector<String>) : Vector<String>
{
    if(null != values)
        Reflect.setField(this.data, DATA_COMPLETE_LEVELS, values);
    return values;
}

OTHER TIPS

You meant this of course (Haxe 3+)

function get_completedLevelKeys() : Vector<String>

function set_completedLevelKeys(values : Vector<String>) : Vector<String>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top