Reputation: 630
I am trying to create a math game, in Adobe Animate, where there is a question and the user types the answer into a text input bar.
I have created my submit button, and added an event listener, however, i am not sure how to compare the input text, and the result, using an If
statement.
I have named my text input "myname"
and here is my code so far:
this.submit.addEventListener("click", check);
function check()
{}
How do i get the input text and compare it to the answer?
Upvotes: 0
Views: 87
Reputation: 15881
Try using the Equality ==
operator to check if they are same (equal)...
function check()
{
if (myname.text == "your result text")
{
trace("user input (myname) is matching...");
}
}
regarding...
"Sorry but this doesn't seem to be working it's not showing any errors it's just no showing the result or printing."
I wonder if this line is causing a problem:
this.submit.addEventListener("click", check);
If you have a Sprite or MovieClip object called (instance name) "submit" then setup code like this:
submit.buttonMode = true;
submit.addEventListener(MouseEvent.CLICK, check);
Then let the compiler know that function check
is supposed to handle mouse events.
function check (evt:MouseEvent)
{
if (myname.text == "your result text")
{
trace("user input (myname) is matching...");
}
}
PS: I personally don't use this.
in front of variable names, but maybe your program setup means you have no choice. In such case, try using this.submit.addEvent...
and this.myname.text ==...
when trying to make it work.
Upvotes: 1