我有这个actionScript3 Code I移植到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);
}
我只是把手弄脏了哈希,我对Reflect有点困惑
Haxe中的等效代码是什么?
答案 0 :(得分:2)
这应该有效:
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;
}
答案 1 :(得分:1)
你的意思当然是(Haxe 3 +)
function get_completedLevelKeys() : Vector<String>
function set_completedLevelKeys(values : Vector<String>) : Vector<String>