2 Replies Latest reply on Jul 19, 2008 3:39 AM by Newsgroup_User

    assign functions

    Level 7

      Hello,

      With the script below I want to assign 10 functions to 10 clips (named
      hitzone1, hitzone2 etc).
      First clip hitzone1 should have the function mc_ball.gotoAndStop(1)
      Second clip hitzone2 should have the function mc_ball.gotoAndStop(2)
      etcetera..

      I dont get it, all the functions seem to be
      mc_ball.gotoAndStop(10)

      I have no idea how to fix this..


      for (var i:Number = 1; i <= 10; i++) {
      zone = "hitzone_" + i;
      _root[zone].onMouseDown = function () {
      mc_ball.gotoAndStop(i);
      }
      }


      Regards,

      Peter


        • 1. Re: assign functions
          rlc5611 Level 1
          Once the for loop is completed, the value of "i" no longer has any significance.

          release

          for (var i:Number = 1; i <= 10; i++) {
          _root["hitzone_" + i].my_i = i;
          _root["hitzone_" + i].onMouseDown = function () {// why not onPress or onRelease???
          mc_ball.gotoAndStop(this.my_i);
          }
          }
          • 2. Re: assign functions
            Level 7
            Thank you rlc5611,

            Transfering the variable i to the clip with "_root["hitzone_" + i].my_i = i;
            " is where i went wrong.
            I assigned a variable to the function instead of a constant. (and
            onmousedown was changed allready, had to be onPress (its a clip not a
            button)

            Regards



            "rlc5611" <webforumsuser@macromedia.com> wrote in message
            news:g5sbi2$fh$1@forums.macromedia.com...
            > Once the for loop is completed, the value of "i" no longer has any
            > significance.
            >
            > release
            >
            > for (var i:Number = 1; i <= 10; i++) {
            > _root["hitzone_" + i].my_i = i;
            > _root["hitzone_" + i].onMouseDown = function () {// why not onPress or
            > onRelease???
            > mc_ball.gotoAndStop(this.my_i);
            > }
            > }
            >
            >
            >