A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: buttons enabled/not enabled problem

  1. #1
    Junior Member
    Join Date
    Oct 2004
    Posts
    12

    buttons enabled/not enabled problem

    I have a problem making a flash rpg game. I was reading many tutorials but I cant seem to do it correctly. I will appreciate any help!

    This should work as follows: I have 100 hours to do some things like work, study etc. and each of these actions will reqire 1 hour to complete. After there will be 0 hours left, the buttons required for performing "work", "study" etc should be disabled.
    Problem: When I reach 0 hours, it then start to count hours left upwards! 1,2,3...

    This is the code:
    // Variables
    var money:Number = 0;
    var hours:Number = 16;

    //Button name :"work" (other buttons will have similar code)
    on (release) {
    money += 100,,
    hours -= 1;
    }

    //Buttons enabled/disabled
    if (hours < 1) {
    work._alpha = 50;
    work.enabled = false;
    } else {
    work._alpha = 100;
    work.enabled = true;
    }

    Once again thanks for any help or suggestions!

  2. #2
    Senior Member jbum's Avatar
    Join Date
    Feb 2004
    Location
    Los Angeles
    Posts
    2,920
    One way to do this is to use a single function for handling deductions from your time pool.

    code:

    ModifyHours = function(amt)
    {
    hours += amt;
    if (hours <= 0) {
    // disable time-related buttons here
    work._alpha = 50;
    }
    else {
    // enable time-related buttons here
    work._alpha = 100;
    }
    }



    This is a common programmer's trick and is called a 'bottleneck' function - the idea is to get all the processing for hours to pass thru that one point.

    Then your individual button handlers look like this:

    code:

    on (release) {
    if (hours > 1)
    {
    money += 100,,
    ModifyHours(-1);
    }
    }




    Then, if there's a way to increase the time pool, you would use something like:

    ModifyHours(1);

  3. #3
    Junior Member
    Join Date
    Oct 2004
    Posts
    12
    Thanks for quick reply! Everything working now

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