Hello, I am trying to get a function to work correctly. The first part of the code works great - when I type 24153 it displays as 1 entry; however, when I access the next function and I type 06310078, each part the number displays on a different line in the output window - like 0, then 6, then 3, etc., the last entry is 06310078. This causes the incorrect action to take place, which is the != code to activate where it should not do so.
Please help!!!
billCode.addEventListener(Event.CHANGE, textChanged);
function textChanged(e:Event)
{
var a:String = billCode.text;
if (billCode.length > 4)
{
stage.focus = transit;
}
/*if (a == "24153")
{
aaa == 0;
}
*/
if (a != "24153")
{
MovieClip(parent).results.wrong4_mc.visible = true;
MovieClip(parent).results.overallIncorrect_mc.visible = true;
MovieClip(parent).results.overallIncorrect_mc.feedback_txt.text = "In order to certify that you can add APO to a contract in RBMS, you must complete all tasks with no errors. Since you made errors, you are not certified. Look at all sections containing the Red X and review the instructions in the DTP again. Then you can retake this scenario at another time.";
}
trace(a);
}
transit.addEventListener(Event.CHANGE, textChanged1);
function textChanged1(e:Event)
{
var b:String = transit.text;
if (transit.length > 7)
{
stage.focus = type;
}
/*if (b == "06310078")
{
bbb == 0;
}
*/
if (b != "06310078")
{
MovieClip(parent).results.wrong4_mc.visible = true;
MovieClip(parent).results.overallIncorrect_mc.visible = true;
MovieClip(parent).results.overallIncorrect_mc.feedback_txt.text = "In order to certify that you can add APO to a contract in RBMS, you must complete all tasks with no errors. Since you made errors, you are not certified. Look at all sections containing the Red X and review the instructions in the DTP again. Then you can retake this scenario at another time.";
}
trace(b);
}
Thanks,
Rober
I want the code to move from text field to text field, based on the maximum number of characters for each field, that is why I have the code stage.focus = _______;
I just tried the code again and when I retyped 24153 it also displayed in the output window as
2
24
241
2415
24153
causing the != function to work when the answer is correct.
Suggestions!!!
makes sense.
yup, looks right.
How do you know this? It looks like all your != condition does is set some things visible and updates some text. But this has already happened for 2 - 2415, so all that stuff is already visible. In fact that condition does nothing new 24+ and you really have no idea if its getting called or not (well, unless you have a breakpoint in there you didn’t mention ).
Hi, I’m sorry I didn’t mention it earlier. I tested the code by pressing Ctrl+Enter and looking at the preview SWF. As I was typing 24153 in the input text field and it began typing the information on multiple lines in the output window. What I want the code to do is to verify that 24153 was typed in the input text field and if was not, then perform the code under !24153. I’d also like the cursor to move to the next input text field. I do not want it to look at the different lines (2, 24, 241, etc). I want it to look at 24153 as the correct answer in its entirety. Hope this makes sense. When I publish the swf file when I type 24153, which is the correct answer, in the applicable field, the != 24153 code takes over instead of what I will revise the == 24153 logic to do.
I still don’t know exactly how you want it to work, but maybe I can point you in the right direction.
- You have nothing that resets the error message. You need to do this at some point so if they have it wrong but later fix it, they’ll know its fixed. Ideally it should reset as they’re fixing it, so when they know its wrong, and maybe backspace a bunch, it goes away then.
- You have two conditions, one that checks length, and a separate, independent one that checks value. Both of these are always run on each text change. The first one checking length always changes focus after so many characters are entered, right or wrong. The other, checking value, always checks the value no matter how many characters are entered. Don’t you only want to change focus when the right characters are entered?
- For the character length, is it OK to have more than that number of characters? Do you really want “>” or do you want “==”? If there is only ever one value that’s correct, and you don’t expect people to be able to enter more characters, it sounds like you want ==, right?
You need to figure out when you want your error message to appear and put that into code. Then you need to know when to clear it so when people do get it right, it doesn’t still say there’s an error. I also don’t know what kind of expectations you have for the people entering this in. Should they know how many characters it should have? If you only show an error on that length, is it giving that away? For those kinds of cases, validation should only occur when they try to submit the full form.
Personally, I’m thinking it would work something like…
if (text == expectedText) {
focusNextField();
hideError();
}else if (text.length == expectedText.length) {
showError();
}else{
hideError();
}
Thank you very much! It has worked great… I really appreciate your help.
Robert.