0 Replies Latest reply on Oct 24, 2007 1:39 AM by absurd29

    avoid repeating a 'for' loop 3 times

    absurd29
      Any ideas how can I make my code more efficient by not repeating the for loop 3 times within a script? Any tutorial links or first hand experience – I’d be grateful for any pointers:


      1) First I use it to set up a drag n’ drop activity:

      for (var i:Number = 0; i<words.length; i++) {
      //set a var for the instances on stage:
      var eachWord:String = "drag"+[i+1]+"_mc";
      this[eachWord].word_txt.text = words [0];

      this[eachWord].onPress = function() {
      startDrag(this, false, leftLimit, topLimit, rightLimit, bottomLimit);

      };
      this[eachWord].onRelease = this[eachWord].onReleaseOutside=function () {
      this.stopDrag();
      };
      }

      2) Then I use it in the part that makes it accessible by keyboard:

      function myOnKeyDown() {
      for (var i:Number = 0; i<words.length; i++) {
      var thisDrag:String = "drag"+[i+1]+"_mc";
      if (Key.isDown …

      ETC along with a listener object


      3) I also have to use it in another function that the user can call to toggle something on/off within each drag object.

      Thanks in advance if anyone can help.