使用Javascript:
function TeamSelection(player_id)
{
var playerInfo = new Object();
playerInfo["info_" + player_id];
}
HAXE: 嘿我试着像这样定义对象:
class TeamSelection
{
var playerInfo : Map<String>;
public function new() {}
public function changeField()
{
playerInfo.set("info_" + player_id, player_name);
}
}
但是我收到编译错误,
我该怎么办?
未婚夫。
答案 0 :(得分:1)
不知道你要做什么,但你必须实例化你的地图
class TeamSelection
{
var player:Player;
// i don't know why you don't stock your players directly..
var playerInfo : Map<String,String>= new Map();// has to be instanciated
public function new() {
//create your player
player= new Player();
player.id=1;
player.name="bob";
}
public function changeField()
{
//make use of string interpolation
playerInfo.set('info_${player.id}',player.name);
}
}
class Player{
public var id:Int;
public var name:String;
public function new(){}
}