Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Having problems comparing with If statement (Basic)

Guest
Jan 06, 2016 Jan 06, 2016

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

TOPICS
ActionScript
926
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Enthusiast , Jan 06, 2016 Jan 06, 2016

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!";

}

}

Translate
Enthusiast ,
Jan 06, 2016 Jan 06, 2016

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!";

}

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Jan 06, 2016 Jan 06, 2016

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Jan 06, 2016 Jan 06, 2016
LATEST

You're welcome and good luck.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines