I’m creating a button in ActionScript by extending flash.display.SimpleButton
The button doesn’t behave as expected, however, when I declare certain variables in the constructor which also happen to exist as properties in the SimpleButton class. They appear to conflict..
Why is this? Shouldn’t the locally declared variables be allowed to co-exist with similarly named class properites?
Snippet below might better illustrate the issue:
public class MyButton extends SimpleButton{
public function MyButton(/*..*/){
var upState:ButtonDisplayState = new ButtonDisplayState(/*..*/));
var downState:ButtonDisplayState = new ButtonDisplayState(/*..*/);
var overState:ButtonDisplayState = new ButtonDisplayState(/*..*/);
var hitTestState:ButtonDisplayState = new ButtonDisplayState(/*..*/);
super(upState, overState, downState, hitTestState);
}
}
The API docs are here (look for upState for example): http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/flash/display/SimpleButton.html#upState
Thanks,
Aodh.
You can’t redeclare already existing variables, local or not. The only place where you can do something like this is method parameters, where you can have same parameter names as local / class variables.
Why don’t you just pass in those states to the constructor directly like:
or alternatively just set them directly after calling
super();like this: