annettegeek
05-11-2007, 03:08 PM
How can I make an alternate keypress listener for button components?
I can't find this one in the documentation.
Here's what I have on stage:
inputText- text input component
enterAnswer - button component
cont - button component
I'd like the user to be able to enter text in the input, press the Return key/click enterAnswer, then press the Returnkey/click cont to move on to the next swf.
Here's my lame code start, which works for button clicks, but not the Return key.
-------------
cont.enabled=false;
enterAnswer.enabled=false;
inputText.addEventListener(TextEvent.TEXT_INPUT, enableEnterButton);
enterAnswer.addEventListener(ComponentEvent.ENTER, checkItOnPressEnter);
enterAnswer.addEventListener(MouseEvent.CLICK, checkItOnClick);
cont.addEventListener(ComponentEvent.ENTER, contButtonOnPressEnter);
cont.addEventListener(MouseEvent.CLICK, contButtonClicked);
function changeStatesAfterSubmit():void {
cont.enabled=true;
enterAnswer.enabled=false;
inputText.enabled=false;
}
function enableEnterButton(event:TextEvent):void {
enterAnswer.enabled=true;
}
function checkIt():void {
trace("check the answer");
changeStatesAfterSubmit();
enterAnswer.removeEventListener(ComponentEvent.ENT ER, checkItOnPressEnter);
inputText.addEventListener(TextEvent.TEXT_INPUT, enableEnterButton);
}
function checkItOnPressEnter(event:ComponentEvent):void {
checkIt();
}
function checkItOnClick(event:MouseEvent):void {
checkIt();
}
function contButtonClicked(event:MouseEvent):void {
trace("clicked Continue");
}
function contButtonOnPressEnter(event:ComponentEvent):void {
trace("hit enterContinue");
}
I can't find this one in the documentation.
Here's what I have on stage:
inputText- text input component
enterAnswer - button component
cont - button component
I'd like the user to be able to enter text in the input, press the Return key/click enterAnswer, then press the Returnkey/click cont to move on to the next swf.
Here's my lame code start, which works for button clicks, but not the Return key.
-------------
cont.enabled=false;
enterAnswer.enabled=false;
inputText.addEventListener(TextEvent.TEXT_INPUT, enableEnterButton);
enterAnswer.addEventListener(ComponentEvent.ENTER, checkItOnPressEnter);
enterAnswer.addEventListener(MouseEvent.CLICK, checkItOnClick);
cont.addEventListener(ComponentEvent.ENTER, contButtonOnPressEnter);
cont.addEventListener(MouseEvent.CLICK, contButtonClicked);
function changeStatesAfterSubmit():void {
cont.enabled=true;
enterAnswer.enabled=false;
inputText.enabled=false;
}
function enableEnterButton(event:TextEvent):void {
enterAnswer.enabled=true;
}
function checkIt():void {
trace("check the answer");
changeStatesAfterSubmit();
enterAnswer.removeEventListener(ComponentEvent.ENT ER, checkItOnPressEnter);
inputText.addEventListener(TextEvent.TEXT_INPUT, enableEnterButton);
}
function checkItOnPressEnter(event:ComponentEvent):void {
checkIt();
}
function checkItOnClick(event:MouseEvent):void {
checkIt();
}
function contButtonClicked(event:MouseEvent):void {
trace("clicked Continue");
}
function contButtonOnPressEnter(event:ComponentEvent):void {
trace("hit enterContinue");
}