dcsimg
A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: Having problems with If statement (Basic)

  1. #1
    Junior Member
    Join Date
    Jan 2016
    Posts
    2

    Question Having problems with If statement (Basic)

    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:

    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

  2. #2
    . fruitbeard's Avatar
    Join Date
    Oct 2011
    Posts
    1,785
    Hi,

    You were almost there, go over the code and see.

    PHP Code:
    var money:Number 0;

    dollar_btn.onPress = function():Void 
    {
        
    money += 1;
        
    box_txt.text String(money);
        
    //checkMoney();// can do it from this button also
    };

    function 
    checkMoney():Void
    {
        
    trace(money);
        if (
    money 5)
        {
            
    box2_txt.text "Yay!";
        }
    }

    check_btn.onPress = function():Void 
    {
        
    checkMoney();
    }; 
    There are other ways of doing the same thing too, if you think about it.

  3. #3
    Junior Member
    Join Date
    Jan 2016
    Posts
    2
    Thank you for the reply! I will try this as soon as I can

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center