1 Reply Latest reply on Jun 12, 2007 3:03 AM by Greg Dove

    The For..i rules?

    FrAgFo0d Level 1
      Hi,

      In my flash document I have a draggable movieclip (instance name Calc)
      When this movieclip enters the area of buttons I want to disable the buttons.
      This is done by the following script:

      onEnterFrame = function() {
      if (Calc.hitTest(button1)) {
      button1.enabled = false;
      } else {
      button1.enabled = true;
      }
      if (Calc.hitTest(button2)) {
      button2.enabled = false;
      } else {
      button2.enabled = true;
      }
      if (Calc.hitTest(button3)) {
      button3.enabled = false;
      } else {
      button3.enabled = true;
      }
      if (Calc.hitTest(button4)) {
      button4.enabled = false;
      } else {
      button4.enabled = true;
      }
      };

      I have got over 7 buttons per frame.
      This script is becomming too long already, let alone when I complete the script for all the buttons.
      What are the rules of an for..i statement so I can shorten this script.

      Thanks,

      Bart



        • 1. Re: The For..i rules?
          Greg Dove Level 4
          try this:

          this.onEnterFrame = function() {
          var numButtons=10; //or whatever
          for (var i=1;i<=numButtons;i++){
          var buttonRef=this["button"+i];
          if (Calc.hitTest(buttonRef)) {
          buttonRef.enabled = false;
          } else {
          buttonRef.enabled = true;
          }
          }
          }