我有一个包含一些常量的类,并将接收一个包含如下数据的对象文字(关联数组):
var ConfigObj:Config = new Config({
"Some" : 10,
"Other" : 3,
"Another" : 5
});
该类如下所示:
public dynamic class Config
{
static public const SomeProperty:String = "Some";
static public const OtherProperty:String = "OtherProperty";
static public const AnotherProperty:String = "AnotherProperty";
public function Config(settings:Object)
{
// Doing some stuff here
}
}
问题是,如何将常量作为键传递,如下所示:
var ConfigObj:Config = new Config({
Config.SomeProperty : 10,
Config.OtherProperty : 3,
Config.AnotherProperty : 5
});
此外,如果可能的话,我想保持它内联。
var MyObj:MyClass = new MyClass({x:1, y:2, z:3});
对我来说,比:
var Temp:Object = new Object();
Temp.x = 1; // Or Temp[x] = 1;
Temp.y = 2; // Or Temp[y] = 2;
Temp.z = 3; // Or Temp[z] = 3;
var MyObj:MyClass = new MyClass(Temp);