How to abstract multiple buttons to use the same function?
Not sure I phrased that right, but here's the deal. I'm building a demo that has a keyboard in it. Obviously, people will type stuff with it and it will go into a dynamic text field.
So I have a full keyboard (a movie clip named "keyboardStandard") made up of button symbols. That is placed in the same frame as the text field. Then I wrote this code, using the Q key ("keyQ"):
Code:
keyboardStandard.keyQ.addEventListener(MouseEvent.CLICK, addQ);
function addQ(ev):void {
enterPlayerID_txt.appendText("Q");
}
This works just fine, the Q goes into the text field. However, I sure as heck don't want to write 26 event listeners, then 26 more functions, even if it is copy paste. That's just gnarly. Plus, there are actually 3 keyboards - a numeric and special char one as well I need to handle.
I seems passing a parameter from the event listener is not doable, so how do I approach this?
TIA