4 Replies Latest reply on Jun 1, 2006 9:31 PM by Newsgroup_User

    how can i simplify this code?

    Level 7
      Hi flasher

      how can i simplify this code and make it more dynamic rather than everytime
      i have to write codes for every single 'ifs'
      thx in advance

      //key1
      mc1.onRelease = function() {
      this.stopDrag();

      if (this.hitTest(t1)) {
      this._x = t1._x+40;
      this._y = t1._y;
      }
      else if (this.hitTest(t2)) {
      this._x = t2._x+40;
      this._y = t2._y;
      }
      else if (this.hitTest(t3)) {
      this._x = t3._x+40;
      this._y = t3._y;
      }
      else if (this.hitTest(t4)) {
      this._x = t4._x+40;
      this._y = t4._y;
      }
      else {
      this._x = 166;
      this._y = 300;
      }
      };


        • 2. Re: how can i simplify this code?
          Level 7
          nsurveyor,

          excellent! code works perfectly....really appreciated it.

          i have another logic puzzle where i need to have a detection..basically:
          i have these 2 draggable objects (mc1 and mc2) and 4 targets (t1, t2, t3,
          t4) to dropped on.
          i need to setup a way where when i drop, eg.: (mc1 and mc2) to t1 or t2, so
          on, to go to a specific movieclip frame. (in this case, inside the mc1 and
          mc2, it will have 5 frames with different colors on each frame for user
          response).

          thx in advance..



          "NSurveyor" <saif7463@yahoo.com> wrote in message
          news:e5nvl8$q5v$1@forums.macromedia.com...
          > Try this:
          >
          > mc1.onRelease = function() {
          > this.stopDrag();
          > var clips = [t1, t2, t3, t4];
          > var hit = false;
          > for (var c = 0; c<clips.length; c++) {
          > var cClip = clips[c];
          > if (this.hitTest(cClip)) {
          > this._x = cClip._x+40;
          > this._y = cClip._y;
          > hit = true;
          > break;
          > }
          > }
          > if (!hit) {
          > this._x = 166;
          > this._y = 300;
          > }
          > };
          >


          • 4. Re: how can i simplify this code?
            Level 7
            perfect! thx for all ur help.
            can i put u as my flash developer contact just in case if there is some
            potential project for us to work on together?
            if u dnt mind, u can send me an email to jidesign@hotmail.com
            cheers.


            "NSurveyor" <saif7463@yahoo.com> wrote in message
            news:e5o56t$2vb$1@forums.macromedia.com...
            > Try...
            >
            > mc1.onRelease = function() {
            > this.stopDrag();
            > var clips = [t1, t2, t3, t4];
            > var hit = false;
            > for (var c = 0; c<clips.length; c++) {
            > var cClip = clips[c];
            > if (this.hitTest(cClip)) {
            > this.gotoAndStop(c+2);
            > this._x = cClip._x+40;
            > this._y = cClip._y;
            > hit = true;
            > break;
            > }
            > }
            > if (!hit) {
            > this._x = 166;
            > this._y = 300;
            > this.gotoAndStop(1);
            > }
            > };
            > mc2.onRelease = mc1.onRelease;
            >