A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: [RESOLVED] variable to control button visibility

  1. #1
    Senior Member
    Join Date
    Nov 2001
    Posts
    111

    resolved [RESOLVED] variable to control button visibility

    hey,

    i have a movieclip called allBUTTONS which contains 18 buttons. This movieclip will be called numerous time on the CDROM I am creating, and each time the number of buttons visible will change.

    So instead of writing the following code numerous times for however many buttons i want visible:

    Code:
    _root.allBUTTONS.button01._visible = true;
    _root.allBUTTONS.button02._visible = true;
    _root.allBUTTONS.button03._visible = true;
    _root.allBUTTONS.button03._visible = false;
    ....I have written the following code:

    Code:
    var buttonNumber:Number = 0; 
    for (var i:Number = 0; i < 6; i++) { 
      buttonNumber++;
      _global.buttonName = "button0"+buttonNumber;
      trace(buttonName);
      }
    and this works fine and traces the following:

    button01
    button02
    button03
    button04
    button05
    button06

    now i thought that i could add the follwing line into the loop:

    _root.allBUTTONS.buttonName._visible = false;

    so I have:

    Code:
    var buttonNumber:Number = 0; 
    for (var i:Number = 0; i < 6; i++) { 
      buttonNumber++;
      _global.buttonName = "button0"+buttonNumber;
      _root.allBUTTONS.buttonName._visible = false;
      trace(buttonName);
      }
    so each time the loop occurs it would turn buttons 1 - 6 invisible. It doesn't work though. Is the syntax wrong? Am I adding the 'buttonName' variable into the line of code in the wrong manner?

    Any help would be greatly appreciated!

    Cheers,

    James

  2. #2
    |-'|-'|
    Join Date
    Jan 2006
    Posts
    273
    maybe try this. didn't test, but maybe it would work.
    Code:
    for(i=1;i<=6;i++){
         b = (i<10) ? '0'+i : i;
         _root.allBUTTONS['button'+b]._visible = false;
    }

  3. #3
    Senior Member
    Join Date
    Nov 2001
    Posts
    111
    that worked perfectly.

    thanks very much for your help....

    james

  4. #4
    |-'|-'|
    Join Date
    Jan 2006
    Posts
    273
    np. btw, that b = yada is just so if you want i<= more than 10. So if you change 6 to 18 it would still work. if you want to just have up to 6 you can always change it to b = '0'+i; simpler.

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