Log in

View Full Version : [FLASH8] AS code for a "Return or Enter" keystoke; how?



FordCorsair
11-11-2008, 10:28 AM
I had no luck on another forum (Flash) with this, and suddenly realised I should have posted here first anyway...

I'm creating a simple memory test, and the user is to memorise the words on screen for a few seconds and then input their answer on the next frame.

http://i52.photobucket.com/albums/g26/FordCorsair/FlashHelp/input1.jpg

1st screen fades away and then 2nd screen comes up where the user is to input the memorised text into a 'dynamic', multiline with wrap textbox and click submit.

http://i52.photobucket.com/albums/g26/FordCorsair/FlashHelp/input2.jpg

However, when user clicks submit they get the cross symbol to show a wrong answer even when they've inputted correctly.

http://i52.photobucket.com/albums/g26/FordCorsair/FlashHelp/input3.jpg

I suspect when the user presses 'return' or 'enter', whilst typing their answer, that key stroke is not accounted for in my answer within the AS code .text == "Blue Chair Two".

This code works fine when the text box is single line.

So, how would I rectify this?

This is my code




tick_mc._x = 244.4;
tick_mc._y = 128.4;
tick_mc._visible = false;
cross_mc._x = 244.4;
cross_mc._y = 128.4;
cross_mc._visible = false;
//
stop();
//
submit_btn.onRelease = function() {
if (wordinput1_txt.text == "Blue Chair Two") {
tick_mc._visible = true;
cross_mc._visible = false;
}else{
cross_mc._visible = true;
}
};



Thanks

BLiZZaRD
11-11-2008, 02:51 PM
Depends on what has focus when they press enter. You can tell by adding this:



TextField.prototype.onKeyDown = function () {
if (Key.getCode() == Key.ENTER) {
// Enter was pressed.
}
};


It can get tricky, some keys are reserved by Flash (such as enter) for other purposes. You can disable/get around/ use them another way, but it can be complicated. For one way, and one likely to help you or at least spark an idea can be found right here (http://www.oreillynet.com/pub/a/javascript/2003/05/20/colinmoock.html?page=1)

FordCorsair
11-18-2008, 11:26 AM
Thanks BLiZZaRD, but for the past few days I've struggled to understand and get my head around the link you posted but I will continue to keep trying.

However, through trial and error I've come about another way of doing my 'three' items list (multiline) input field (I used 3 separate single line input boxes) and then all to be checked by the submit button whether they're correct or not. I just happened to try '&&' in my code to see what it would do...



tick_mc._x = 274.5;
tick_mc._y = 142.5;
tick_mc._visible = false;
cross_mc._x = 274.5;
cross_mc._y = 142.5;
cross_mc._visible = false;
//
stop();
//
submit_btn.onRelease = function() {
if
(wordinput1_txt.text == "Blue" && wordinput2_txt.text == "Chair" && wordinput3_txt.text == "Two")
{
tick_mc._visible = true;
cross_mc._visible = false;
}else{
tick_mc._visible = false;
cross_mc._visible = true;
}

};



It may seem bit of a fudge but it works... and will do for now.

Medyman
11-18-2008, 01:11 PM
ForCorsair, for something that simple, I would recommend the option that you chose. But, if this is part of a larger, more complicated whole, you might want to look into regular expressions in AS.