Hey people,
I’m working in AS 2.0 all the way now, and I’ve ran into some problems with event handling of UI MX04 Components. Stripped down code I have:
import mx.controls.Button;
class Foo{
...
// aButton is set during the initializing process
...
private var aButton:Button;
public function aButtonClickHandler():Void{
trace("clicked");
}
private function setHandlers():Void{
aButton.addEventListener("click",aButton);
aButton.click = Delegate.create(this,aButtonClickHandler);
}
}
Nothing wrong with the code, but the compiler gives an error stating that the property ‘click’ wasn’t found in aButton. It doesn’t let me allow my handler for the click event I just made it listen to. In this case you can get around it using onRelease, but with other events such as ‘change’ for a ComboBox, there is no alternative like onChange as far as I know.
When I omit the :Button strict data definition, it works. Though I do not want to do that, because I want to keep my code tidy and clean by using strict data definitions, and because I don’t want to evade the problem.
The fix I found for this is to define the click method through associative array referencing: aButton[“click”] = Delegate.create(this,aButtonClickHandler). This works, which proves that the code itself isn’t wrong, but rather the compiler that seems to have disregarded the fact that I added a click event for the component to listen to, and therefore it should allow me to set the click event. Now I need to fool the compiler through the associative array referencing.
Can anyone confirm this ?