3 Replies Latest reply on Jan 6, 2008 6:10 PM by kglad

    Further help with loops

    Level 7
      Hello,

      I've been writing some code for several MC instances in my movie. The code
      is very repetitive in many ways but I'm not entirely sure how it can be
      optimized with loops (although I believe it can be done). This script is
      placed on the 1st frame of the main timeline:

      off_drag2.onPress = function():Void {
      this.startDrag();
      };
      off_drag2.onRelease = off_drag2.onReleaseOutside=function ():Void {
      this.stopDrag();
      for (var i=1; i<15; i++){
      if (eval(this._droptarget) == _root["off_drag"+i]) {
      myHit = 1;
      }
      }
      if (eval(this._droptarget) != mc_bkg) {
      if (myHit != 1){
      off_drag2._x = -400;
      off_drag2._y = -400;
      mc_choices.drag2._x = mc_choices.drag2_x;
      mc_choices.drag2._y = mc_choices.drag2_y;
      }
      }
      myHit = 0;
      };


      off_drag3.onPress = function():Void {
      this.startDrag();
      };
      off_drag3.onRelease = off_drag3.onReleaseOutside=function ():Void {
      this.stopDrag();
      for (var i=1; i<15; i++){
      if (eval(this._droptarget) == _root["off_drag"+i]) {
      myHit = 1;
      }
      }
      if (eval(this._droptarget) != mc_bkg) {
      if (myHit != 1){
      off_drag3._x = -400;
      off_drag3._y = -400;
      mc_choices.drag3._x = mc_choices.drag3_x;
      mc_choices.drag3._y = mc_choices.drag3_y;
      }
      }
      myHit = 0;
      };


      off_drag4.onPress = function():Void {
      this.startDrag();
      };
      off_drag4.onRelease = off_drag4.onReleaseOutside=function ():Void {
      this.stopDrag();
      for (var i=1; i<15; i++){
      if (eval(this._droptarget) == _root["off_drag"+i]) {
      myHit = 1;
      }
      }
      if (eval(this._droptarget) != mc_bkg) {
      if (myHit != 1){
      off_drag4._x = -400;
      off_drag4._y = -400;
      mc_choices.drag4._x = mc_choices.drag4_x;
      mc_choices.drag4._y = mc_choices.drag4_y;
      }
      }
      myHit = 0;
      };

      Any ideas?

      Many thanks.

      CPG