0

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 ?

yannicuLar
  • 3,083
  • 3
  • 32
  • 50
  • What is the private var for? It doesn't seem like it is used at all. – Franco Ponticelli May 06 '14 at 21:06
  • You're right, I was probably meaning to check if null in get/set, and update the private var accordingly when I designed the Class. But while implementing it I realized I don't need to update this var, just the .data object. I'll think about removing the private Declaration. Thank you for your answer ! – yannicuLar May 07 '14 at 06:41

2 Answers2

2

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;
}
Franco Ponticelli
  • 4,430
  • 1
  • 21
  • 24
1

You meant this of course (Haxe 3+)

function get_completedLevelKeys() : Vector<String>

function set_completedLevelKeys(values : Vector<String>) : Vector<String>
bubblebenj
  • 116
  • 2