1 Reply Latest reply on Jun 20, 2006 3:08 AM by 2m

    using 'this' in a function

    absurd29
      I have a function ('checkDrop') which I call in ‘onRelease’ for several draggable MCs. At present I’ve hard coded each draggable
      MC , eg:
      drag2_mc.onRelease = function() {
      stopDrag();
      checkDrop();
      if (HITtest == 2 or HITtest == 1) {
      this.gotoAndStop("_down");
      this.enabled = false;
      this._y = 115;
      }
      }

      It’s more sensible to put the 'if' statement in the function as this part is the same for every draggable MC (& there are about 20!), but using ‘this’ when the lines are placed in the function no longer references the draggable MC. Any ideas how I can reference them all in this way without naming each one individually. (I thought when a function was called, the ‘this’ referred to the object it was being called on – obviously not! - And I really thought I was getting the hang of things.)
      Attached function code if needed.
      Many thanks in advance if anyone can help at all :-)

        • 1. Re: using 'this' in a function
          2m Level 2
          make it:
          drag2_mc.onRelease = function() {
          stopDrag();
          checkDrop(this);
          }

          and your function:

          function checkDrop(clip) {
          //this line just defines the drop area from an array:
          if (_xmouse>cDrop[0] && _ymouse>cDrop[1] && _xmouse<(cDrop[0]+cDrop[2]) && _ymouse<(cDrop[1]+cDrop[3])) {
          HITtest = 2;
          //if following 3 lines are placed here instead of in the draggable MC, it doesn’t work ‘cos ‘this’ no longer refers to the MC being dragged:
          clip.gotoAndStop("_down");
          clip.enabled = false;
          clip._y = 115;

          } else if (_xmouse>ncDrop[0] && _ymouse>ncDrop[1] && _xmouse<(ncDrop[0]+ncDrop[2]) && _ymouse<(ncDrop[1]+ncDrop[3])) {
          HITtest = 1;

          }
          }