目前我有一个类需要来自另一个类的信息,但是必须在运行时根据其他变量确定哪个类。AS3 - 通过变量访问类信息
实际上,我需要我的班级BUTTON.as才能访问GUN(1-9).as,而不必知道它会是什么数字。
我假定将工作的代码是这样的:
public function enableButton(shortcut:int):void{
trace(ID)
dtf_ammo.text = gun[ID].ammo
refreshThis(shortcut, true)
this.alpha = 1
isActive = true
}
ID是类的数量(在这种情况下,gun1)。
下不工作:
public function enableButton(shortcut:int):void{
trace(ID)
dtf_ammo.text = gun1.ammo
refreshThis(shortcut, true)
this.alpha = 1
isActive = true
}
然而,因为有9枪,仅1的按钮,我需要能够使用该ID变量中访问功能类。
这是可能的,如果不是有办法做我想在这里做什么?
你试图访问类静态变量?实例变量? –
我正试图访问静态。公共静态变量ammo:int = 999 –