Currently I have an Array that is having 9 buttons pushed to it. This is called BAR.as:
public static var buttonArray: Array = new Array()
for(var i:int = 0; i<9; i++){
barButton = new button
buttonArray.push(barButton)
buttonArray[i].name = button+(String[i])
buttonArray[i].x = 15+(i*buttonArray[i].width)
addChild(buttonArray[i])
}
Within the class for my button I have specified an enableButton function, this is called ACTIONBARBUTTON.as:
public static function enableButton(shortcut:int):void{
//instance.refreshThis(shortcut, true)
trace("test")
}
What I am trying to do is have a function that I can call to enable/disable these buttons (but not just simply “.enable”/”.disable”) on demand, as the content within them needs to change often. My way to do this was going to be through BAR.as:
public static function updateWeapons(level: int):void{
buttonArray[level-1].enableButton(level)
}
However, this returns the following error:
ReferenceError: Error #1069: Property enableButton not found on src.actionbar.button and there is no default value.
at src.actionbar::bar$/updateWeapons()
at src.game::player$/levelup()
at src.game::gameplay/init()
at flash.display::DisplayObjectContainer/addChildAt()
at src.camera::control()
at flash.display::Sprite/constructChildren()
at flash.display::Sprite()
at flash.display::MovieClip()
Just running button.enableButton(1) works fine.
You can’t call a static member function on an instance of a class.
That’s why this :
Doesn’t work. Make the enableButton function non static and it should work.
Works fine because you are using the class name “button” to invoke the function.