0 Replies Latest reply on May 6, 2006 9:16 AM by DPSwebmaster

    responsive object test not working

    DPSwebmaster Level 1
      I am working on a tutorial found in the AS Bible for flash 8 which is suposed to create a square which responds to your mouse movement by dragging part of the square to change it's shape.

      The script works partially, but not all the way. When loading initially the square is already altered and doesn't respond to the mouse to change it's shape.

      There is also a portion of the script which changes the color of the square when you mouse over a menu on the left hand side and this works fine.

      Here is my code:

      import DrawingUtilities;

      var aColors:Array = [0xFEEFD6, 0xEDFED6, 0xDED7FD,
      0xFED6ED, 0xFFD5D5];
      var nSelectedColor:Number = aColors[0];
      var oSides bject = new Object();
      var oColors bject = new Object();
      var mCurrent:MovieClip;
      var nInterval:Number;

      oSides.mRight = {y:0, x:110, rotation:90};
      oSides.mBotom = {y:100, x:0, rotation:0};
      oSides.mLeft = {y:0, x:0, rotation:90};
      oSides.mTop = {y:-10, x:0, rotation:0};

      makeColorOptions(aColors);
      makeBoxAndSides(aSides);
      drawSquare();

      function makeBoxAndSides():Void{
      this.createEmptyMovieClip("mShape",
      this.getNextHighestDepth());
      mShape.createEmptyMovieClip("mBox",
      mShape.getNextHighestDepth());
      var mSide:MovieClip;
      var duDrawer: DrawingUtilities;
      for (var sSide:String in oSides) {
      mSide = mShape.createEmptyMovieClip(sSide,
      mShape.getNextHighestDepth());
      duDrawer = new DrawingUtilities(mSide);
      duDrawer.lineStyle (0,0,0);
      duDrawer.beginFill(0,0);
      duDrawer.drawRectangle(100, 10, 50, 5);
      mSide.useHandCursor = false;
      mSide.onRollover = function():Void {
      if(mCurrent == this) {
      return;
      }
      resetSide(mCurrent);
      mCurrent = this;
      this.startDrag(true);
      nInterval = setInterval(drawSquare, 10);
      };
      resetSide(mSide);
      }
      addBoxMethod();
      drawsquare();
      mShape._x = Stage.width/2 -mShape._width/2;
      mShape._y = Stage.width/2 -mShape._height/2;
      }

      function resetSide(mSide:MovieClip):Void {
      mSide._y = oSides[mSide._name].y;
      mSide._x = oSides[mSide._name].x;
      mSide._rotation = oSides[mSide._name].rotation;
      mSide.stopDrag();
      clearInterval (nInterval);
      }

      function makeColorOptions (aColors:Array) :Void {
      for (var i:Number = 0; i < aColors.length; i++) {
      mSwatch = this.createEmptyMovieClip(
      "mColorSwatch" + i, this.getNextHighestDepth());
      oColors[mSwatch._name] = aColors ;
      duDrawer = new DrawingUtilities(mSwatch);
      duDrawer.beginFill(aColors
      , 100);
      duDrawer.drawRectangle(15, 15, 7.5, 7.5);
      duDrawer.endFill();
      mSwatch._x = 30;
      mSwatch._y = 20 * i + 30;
      mSwatch.onRelease = function():Void {
      nSelectedColor = oColors[this._name];
      drawSquare();
      };
      }
      }

      function drawSquare():Void {
      var oRight bject = {x:mShape.mRight._x - 10,
      y: mShape.mRight._y};
      var oBottom bject = {x:mShape.mBottom._x,
      y: mShape.mBottom._y};
      var oleft bject = {x: mShape.mLeft._x, y: mShape.mLeft._y};
      var oTop bject = {x: mShape.mTop._x, y: mShape.mTop._y + 10};
      var nMx:Number = mShape.mBox._xmouse;
      var nMy:Number = mShape.mBox._ymouse;
      switch (mCurrent._name) {
      case "mRight":
      if(nMx > 110) {
      resetSide(mCurrent);
      mCurrent = null;
      }
      if(nMx < 25) {
      nMx = 25;
      }
      else if(nMx > 100) {
      nMx = 100;
      }
      if (nMy < 25) {
      nMy = 25;
      }
      else if(nMy > 75) {
      nMy = 75;
      }

      oRight.x = 2*nMx - 100;
      oRight.y = 2*nMy - 50;
      break;
      case "mBottom":
      if(nMy > 110) {
      resetSide(mCurrent) ;
      mCurrent = null;
      }
      if(nMx < 25) {
      nMx = 25;
      }
      else if(nMx > 75) {
      nMx = 75;
      }

      if(nMy < 25) {
      nMy = 25;
      }
      else if(nMy > 100) {
      nMy= 100;
      }
      oBottom.x = 2*nMx - 50;
      oBottm.y = 2*nMy - 100;
      break;
      case "mLeft":
      if(nMx < -10) {
      resetSide (mCurrent);
      mCurrent = null;
      }
      if(nMx < 0) {
      nMx = 0;
      }

      else if(nMx > 75) {
      nMx = 75;
      }

      if(nMy < 25) {
      nMy = 25;
      }
      oLeft.x = 2*nMx;
      oLeft.y = 2*nMy - (.5 * 100);
      break;
      case "mTop":
      if(nMy < -10) {
      resetSide(mCurrent);
      mCurrent = null;
      }
      if (nMx < 25) {
      nMx = 25;

      }

      else if (nMx > 75) {
      NMx = 75;
      }

      if(nMy < 0) {
      nMy = 75;
      }
      oTop.x = 2*nMx - (.5 * 100);
      oTop.y = 2*nMy;
      break;
      }
      mShape.mBox.clear();
      mShape.mBox.lineStyle(0, 0, 100);
      mShape.mBox.beginFill (nSelectedColor, 100);
      mShape.mBox.curveTo(oTop.x, oTop.y, 100, 0);
      mShape.mBox.curveTo(oRight.x, oRight.y, 100, 100);
      mShape.mBox.curveTo(oBottom.x, oBottom.y, 0, 100);
      mShape.mBox.curveTo(oLeft.x, oLeft.y, 0, 0);
      mShape.mBox.endFill();
      updateAfterEvent();
      }


      I was hoping someone could see what is going wrong here.