Copy link to clipboard
Copied
Hello folks,
I have tried searching for an answer for this issue, but I haven't had any luck finding something that actually matches the issue.
I have created three input text boxes with the instance names: input001, input002, and input003.
The three boxes are used for a simple text value comparison for a question exercise.
The input text boxes have been input restricted so that only the values A, B, C, or D can be entered (representing the four possible answers).
I created a button and event listener, and the following function.
function submitBtn001Click(evt:MouseEvent):void{
trace("input001 = "+input001.text+" input002 = "+input002.text+" input003 = "+input003.text);
if(input001.text == "A" && input002.text == "D" && input003.text == "C"){
input001.type = "dynamic";
input002.type = "dynamic";
input003.type = "dynamic";
correct.alpha = 1;
submit_btn.visible = false;
}else if((input001.text !== "A" | input002.text !== "D" | input003.text !== "C") && tryAgain == 1){
tryAgain++;
trace(tryAgain);
submit_btn.visible = false;
reset_btn.visible = true;
incorrect_first_try.alpha = 100;
}else if((input001.text !== "A" | input002.text !== "D" | input003.text !== "C") && tryAgain >= 2){
input001.type = "dynamic";
input002.type = "dynamic";
input003.type = "dynamic";
incorrect.alpha = 100;
submit_btn.visible = false;
}
}
When I compile the SWF, I get the following error:
1067: Implicit coercion of a value of type Boolean to an unrelated type Number. |
The error is traced to the else if statements. If I comment out the else if statements, the SWF compiles without error and the code runs properly when I enter the correct answers in the input boxes (A, D, C).
What I don't understand is why my string comparisons in the else if statements are generating an error, or why that error would have anything to do with Boolean or Number, since I am comparing the text string value of the input boxes (input001.text, for example) with a string.
Thank you in advance for your assistance.
USe the logical OR operator ( || ) instead of the bitwise OR ( | )
Copy link to clipboard
Copied
How do you define tryAgain?
You might consider using != instead of !==
unrelated... incorrect_first_try.alpha = 100; should be 1, not 100
Copy link to clipboard
Copied
Thanks for the reply Ned.
To answer your questions:
tryAgain is defined as:
var tryAgain = 1;
I did indeed try using != but there was no difference. I still received the same error.
I also noted the alpha error immediately after posting and corrected it. The joys of converting AS2 to AS3
I am pretty stumped on this one, honestly. It should be working just fine.
Here is the full code from start to finish. The errors are identified on lines 22 and 28.
import flash.events.MouseEvent;
input001.restrict = "A,B,C,D";
input002.restrict = "A,B,C,D";
input003.restrict = "A,B,C,D";
var tryAgain = 1;
reset_btn.visible = false;
submit_btn.addEventListener(MouseEvent.CLICK, submitBtn001Click);
reset_btn.addEventListener(MouseEvent.CLICK, resetBtn001Click);
function submitBtn001Click(evt:MouseEvent):void{
trace("input001 = "+input001.text+" input002 = "+input002.text+" input003 = "+input003.text);
if(input001.text == "A" && input002.text == "D" && input003.text == "C"){
input001.type = "dynamic";
input002.type = "dynamic";
input003.type = "dynamic";
correct.alpha = 1;
submit_btn.visible = false;
}else if((input001.text !== "A" | input002.text !== "D" | input003.text !== "C") && tryAgain == 1){
tryAgain++;
trace(tryAgain);
submit_btn.visible = false;
reset_btn.visible = true;
incorrect_first_try.alpha = 1;
}else if((input001.text !== "A" | input002.text !== "D" | input003.text !== "C") && tryAgain >= 2){
input001.type = "dynamic";
input002.type = "dynamic";
input003.type = "dynamic";
incorrect.alpha = 1;
submit_btn.visible = false;
}
}
function resetBtn001Click(evt:MouseEvent):void{
input001.text = "";
input002.text = "";
input003.text = "";
incorrect_first_try.alpha = 0;
submit_btn.visible = true;
reset_btn.visible = false;
}
stop();
Again, I appreciate the suggestions. I have two of these particular items to convert, and need to solve this one to get the other finished and get this project completed.
Copy link to clipboard
Copied
USe the logical OR operator ( || ) instead of the bitwise OR ( | )
Copy link to clipboard
Copied
That was it, Ned... I had thought it had something to do with the OR operator, but to be honest, I have never used anything but the bitwise OR.
Of course, AS2 is much more forgiving.
Than you again... was able to complete that last piece and get it out the door!
Copy link to clipboard
Copied
You're welcome
Find more inspiration, events, and resources on the new Adobe Community
Explore Now