10 Replies Latest reply on Aug 19, 2009 1:55 PM by kglad

    help with condensing button code

    DPSwebmaster Level 1



      I have a grid, consisting of 16 rows, seven columns. So there are 7 buttons in each row. i have on the buttons an instance name such as ButtonClick1_1, ButtonClick1_2, ButtonClick1_3,ButtonClick1_4 etc and for the second row ButtonClick2_1, ButtonClick2_2 etc.


      for my AS code, the action is the same for each button. I currently have a ton of code such as the following.


      ButtonClick1_1.addEventListener(MouseEvent.CLICK, clickHandler1);
      function clickHandler1(event:MouseEvent):void {
      ButtonClick1_1.alpha=0; // 50% alpha


      ButtonClick1_2.addEventListener(MouseEvent.CLICK, clickHandler2);
      function clickHandler2(event:MouseEvent):void {
      ButtonClick1_2.alpha=0; // 50% alpha


      ButtonClick1_3.addEventListener(MouseEvent.CLICK, clickHandler3);
      function clickHandler3(event:MouseEvent):void {
      ButtonClick1_3.alpha=0; // 50% alpha



      I am doing it that way for 112 buttons! I know there is way to simplify this with a for loop, but am not sure how to code it. Any ideas?