Copy link to clipboard
Copied
hai, this is my code. everytime i answer correct answer which is "oksigen" it will show inccorect alert, but if i change from if(input1.text == "oksigen") to if(input1.text = "oksigen") then i will shpw the correct alert. why this happen? i already recheck all the instance name and everything just fine. Please help. Thank you.
stop();
import flash.events.MouseEvent
btnSemak01.addEventListener(MouseEvent.CLICK, bilaKlik);
function bilaKlik(event:MouseEvent): void
{
if(input1.text == "oksigen")
{
jawapanPelajar1.text = "congratulation, your answer is correct";
}
else
{
jawapanPelajar1.text = "sorry, please try again";
}
}
Thank you for the very simple example file.
I wonder if the right answer should be carbondioxide, and not oxygen, but that aside, your input field has a character it it already, and the user answer adds to the end of the text. Try this:
stop();
import flash.events.MouseEvent
btnCheck.addEventListener(MouseEvent.CLICK, onClik);
input.text = "";
function onClik(event: MouseEvent): void {
if (input.text == "oksigen") {
answer.text = "Tahniah, jawapan anda betul";
} else {
answer.text = "
...
Copy link to clipboard
Copied
forgot to tell. if i change from "==" to "=" i will get the error. and i know it because the correct whay is "==" not "="
Copy link to clipboard
Copied
Hi.
Your code is correct. I run a test here and everything works just fine.
Do you have an FLA to share so we can investigate better?
Also, you should never use the assignment operator (=) in if statements. You should use the equality operator (==) or the strict equality operator (===) for cases like yours.
Here is a complete list of AS3 operators.
Regards,
JC
Copy link to clipboard
Copied
the correct answer should be oksigen but it show incorrect alert "Maaf, sila cuba lagi" instead of correct alert Tahniah, jawapan anda betul"
Copy link to clipboard
Copied
You may need to set the permissions on that file so that anyone with the link can download it.
Copy link to clipboard
Copied
sorry. just change the permission
Copy link to clipboard
Copied
Thank you for the very simple example file.
I wonder if the right answer should be carbondioxide, and not oxygen, but that aside, your input field has a character it it already, and the user answer adds to the end of the text. Try this:
stop();
import flash.events.MouseEvent
btnCheck.addEventListener(MouseEvent.CLICK, onClik);
input.text = "";
function onClik(event: MouseEvent): void {
if (input.text == "oksigen") {
answer.text = "Tahniah, jawapan anda betul";
} else {
answer.text = "Maaf, sila cuba lagi";
}
}
Copy link to clipboard
Copied
Thank you. btw, the questions is beside sugar what are the product of photosynthesis. so, the answer is oxygen.
Copy link to clipboard
Copied
Ah! It was the 'product' of photosynthesis. I was reading it as what was needed for photosynthesis. I wish I knew Malayan better.
Copy link to clipboard
Copied
stop();
import flash.events.MouseEvent
btnCheck.addEventListener(MouseEvent.CLICK, onClik);
function onClik(event:MouseEvent): void
{
if(input.text == "oksigen")
{
answer.text = "Tahniah, jawapan anda betul";
}
else
{
answer.text = "Maaf, sila cuba lagi";
}
}