Copy link to clipboard
Copied
Hi, at school we are learning to use Flash and we are using AS2, and I was working on an example code, but it doesn't seem to want to work. Here is the code:
var money:Number=0;
dollar_btn.onPress=function()
{
money+=1;
box_txt.text=money;
}
if(money>5){
check_btn.onPress=function()
{
box2_txt.text="Yay!";
}
}
As you can see, all I want to do is have a button, that once pressed, adds 1 to the money counter, and one it is higher than 5, I can press the next button and have it display "Yay!". The problem is, the if doesn't seem to work, even if the money variable is way above 5. I don't think it's a problem with the buttons, because I have tried changing the code to declare the variable with a starting value of 6, and the If works. Any ideas? It would be greatly appreciated !
Thanks in advance
Put the if() statement inside the function:
var money:Number=0;
dollar_btn.onPress=function()
{
money+=1;
box_txt.text=money;
}
check_btn.onPress=function()
{
if(money>5){
box2_txt.text="Yay!";
}
}
Copy link to clipboard
Copied
Put the if() statement inside the function:
var money:Number=0;
dollar_btn.onPress=function()
{
money+=1;
box_txt.text=money;
}
check_btn.onPress=function()
{
if(money>5){
box2_txt.text="Yay!";
}
}
Copy link to clipboard
Copied
Wow! Thank you so much! I've been having trouble with this for multiple days and I can finally continue my work! I'm surprised it's so simple . +1
Copy link to clipboard
Copied
You're welcome and good luck.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now