Copy link to clipboard
Copied
Ned Murphy (or anyone else),
I referenced some guidance you offered a while back concerning combining functions. Your response was:
Mar 19, 2012 6:45 AM in reply to witherton
You do not want to be using the same name for a function and a variable. As far as combining the two functions, it would make sense to just have the doorColor function do all the work, though you do not need to use the if/else setup...
var min = 1;
var max = 3;
function doorColor (event:MouseEvent)
{
var getNewDoor:Number = Math.round(Math.random() * (max - min) + min);
gotoAndStop("door"+String(getNewDoor));
}
I'm building a program with a similar need to combine functions. I've got text input fields (answerBox and answerBox2). I'm forcing the user to go to the first input text field with stage.focus = answerBox2.
I used most of the code you recommended to witherton in my coding. My desire is to combine the input from the two text fields to jump to a "Correct or "Incorrect" page once Enter is clicked.
I included my coding to show you where I'm at. Not sure if I inserted your snippet in the right place...for Line 68, I keep getting a 1083: Syntax error: else is unexpected.
46 stop();
47
48 answerBox2.text = "";
49 stage.focus = answerBox2;
50 answerBox.text = "";
51 stage.focus = answerBox;
52
53 stage.addEventListener(KeyboardEvent.KEY_DOWN, keyPressed);
54
55 function keyPressed(evt:KeyboardEvent):void {
56 if (evt.keyCode == Keyboard.ENTER) {
57 if (answerBox2.text == "+80" || answerBox2.text == "+ 80" || answerBox2.text == "OVER 80" || answerBox2.text == "OVER80"|| answerBox2.text == "over 80" || answerBox2.text == "over80") {
58 //gotoAndStop(20); I previously used this for a single function
59 } else {
60 if (answerBox2.text != "") {
61 //gotoAndStop(19); I previously used this for a single function
62 if (answerBox.text == "R390" || answerBox.text == "R 390" || answerBox.text == "RIGHT390" || answerBox.text == "RIGHT 390"|| answerBox.text == "right 390" || answerBox.text == "right390") {
63 var answerBox2 = error1;
64 var answerBox = error2;
65 function TwoErrors(event:MouseEvent) {
66 var getTwoErrors:Keyboard.ENTER = Math(Math() * (error1 + error2));
67 gotoAndStop(20);
68 } else {
69 if (answerBox2.text + answerBox.text != "") {
70 gotoAndStop(19);
71 }
72 }
73 }
74 }
75 }
76 }
77 }
I tried adding and deleting curly brackets at different lines, but the error is still there. Can you assist?
Thanks!
I'm really showing my inner noob, eh?
Copy link to clipboard
Copied
What is the error message?
Copy link to clipboard
Copied
Line 68 1083: Syntax error: else is unexpected.
Copy link to clipboard
Copied
What are you trying to accomplish with the lines:
63 var answerBox2 = error1;
64 var answerBox = error2;
If those are the textfields names, then you don't want to be creating variables that are named the same as the textfields.
Also, you appear to have a function nested within another function. Don't do that.
Copy link to clipboard
Copied
With lines 63 & 64, I'm hoping to identify what variables are to be combined/considered before a click on the 'Enter' key will take you to a 'Correct' or 'Incorrect' page.
Doh! Of course you're right about the nested function. I'll try to separate them before moving on.
Thanks!
Find more inspiration, events, and resources on the new Adobe Community
Explore Now