3 Replies Latest reply on May 27, 2009 3:02 PM by Ned Murphy

    Drag & Snap Puzzle Problem Again

    learner102

      I have re-tooled a flash drag and snap puzzle game so instead of using dragable buttons i now have movie clips that snap into place.  That part works...My issue is that when all the pieces are in place a message should pop up and say "Great Job!" in a dynamic text box with an istance name of 'message'.  That part doesn't work.  I have gotten great insight from this forum so if someone could look at the code below and show me how to fix the problem I would be indebted.  The code is all on one frame in the main time line and there are 8 pieces to the puzzle:

       

      piece1.onPress = function(){
      this.swapDepths ( this._parent.getNextHighestDepth( ) );
      piece1.startDrag();
      }
      piece1.onRelease = function(){
      piece1.stopDrag();
      if (piece1._x >321 && piece1._x < 371 && piece1._y >164 && piece1._y <214)
      // if puzzle pieces is within the boundaries of the puzzle then snap!
      {
      if(!this.completed){
      _root.completedPuzzleCheck(); // add this to each of your pieces
      this.completed=true;
      }

      setProperty("piece1", _x,"346.6")
      setProperty("piece1", _y,"189.8")

      } else {
      if(this.completed){
      this.completed=false;
      _root.numCompleted--;
      }
      }
      }


      piece2.onPress = function(){
      this.swapDepths ( this._parent.getNextHighestDepth( ) );
      piece2.startDrag();
      }
      piece2.onRelease = function(){
      piece2.stopDrag();
      if (piece2._x >243 && piece2._x < 293 && piece2._y >121 && piece2._y <171)
      // if puzzle pieces is within the boundaries of the puzzle then snap!
      {
      if(!this.completed){
      _root.completedPuzzleCheck(); // add this to each of your pieces
      this.completed=true;
      }

      setProperty("piece2", _x,"268.2")
      setProperty("piece2", _y,"146.9")

      } else {
      if(this.completed){
      this.completed=false;
      _root.numCompleted--;
      }
      }
      }

      piece3.onPress = function(){
      this.swapDepths ( this._parent.getNextHighestDepth( ) );
      piece3.startDrag();
      }
      piece3.onRelease = function(){
      piece3.stopDrag();
      if (piece3._x >202 && piece3._x < 252 && piece3._y >84 && piece3._y <134)
      // if puzzle pieces is within the boundaries of the puzzle then snap!
      {
      if(!this.completed){
      _root.completedPuzzleCheck(); // add this to each of your pieces
      this.completed=true;
      }

      setProperty("piece3", _x,"227.3")
      setProperty("piece3", _y,"109.2")

      } else {
      if(this.completed){
      this.completed=false;
      _root.numCompleted--;
      }
      }
      }

      piece4.onPress = function(){
      this.swapDepths ( this._parent.getNextHighestDepth( ) );
      piece4.startDrag();
      }
      piece4.onRelease = function(){
      piece4.stopDrag();
      if (piece4._x >295 && piece3._x < 345 && piece4._y >76 && piece3._y <149)
      // if puzzle pieces is within the boundaries of the puzzle then snap!
      {
      if(!this.completed){
      _root.completedPuzzleCheck(); // add this to each of your pieces
      this.completed=true;
      }

      setProperty("piece4", _x,"320.9")
      setProperty("piece4", _y,"101.8")

      } else {
      if(this.completed){
      this.completed=false;
      _root.numCompleted--;
      }
      }
      }

      piece5.onPress = function(){
      this.swapDepths ( this._parent.getNextHighestDepth( ) );
      piece5.startDrag();
      }
      piece5.onRelease = function(){
      piece5.stopDrag();
      if (piece5._x >392 && piece5._x < 442 && piece5._y >148 && piece5._y <198)
      // if puzzle pieces is within the boundaries of the puzzle then snap!
      {
      if(!this.completed){
      _root.completedPuzzleCheck(); // add this to each of your pieces
      this.completed=true;
      }

      setProperty("piece5", _x,"417.1")
      setProperty("piece5", _y,"173.4")

      } else {
      if(this.completed){
      this.completed=false;
      _root.numCompleted--;
      }
      }
      }

      piece6.onPress = function(){
      this.swapDepths ( this._parent.getNextHighestDepth( ) );
      piece6.startDrag();
      }
      piece6.onRelease = function(){
      piece6.stopDrag();
      if (piece6._x >347 && piece6._x < 397 && piece6._y >45 && piece6._y <95)
      // if puzzle pieces is within the boundaries of the puzzle then snap!
      {
      if(!this.completed){
      _root.completedPuzzleCheck(); // add this to each of your pieces
      this.completed=true;
      }

      setProperty("piece6", _x,"372.3")
      setProperty("piece6", _y,"70.8")

      } else {
      if(this.completed){
      this.completed=false;
      _root.numCompleted--;
      }
      }
      }

      piece7.onPress = function(){
      this.swapDepths ( this._parent.getNextHighestDepth( ) );
      piece7.startDrag();
      }
      piece7.onRelease = function(){
      piece7.stopDrag();
      if (piece7._x >260 && piece7._x < 310 && piece7._y >33 && piece7._y <83)
      // if puzzle pieces is within the boundaries of the puzzle then snap!
      {
      if(!this.completed){
      _root.completedPuzzleCheck(); // add this to each of your pieces
      this.completed=true;
      }

      setProperty("piece7", _x,"285.7")
      setProperty("piece7", _y,"58.4")

      } else {
      if(this.completed){
      this.completed=false;
      _root.numCompleted--;
      }
      }
      }

      piece8.onPress = function(){
      this.swapDepths ( this._parent.getNextHighestDepth( ) );
      piece8.startDrag();
      }
      piece8.onRelease = function(){
      piece8.stopDrag();
      if (piece8._x >431 && piece8._x < 481 && piece8._y >106 && piece8._y <156)
      // if puzzle pieces is within the boundaries of the puzzle then snap!
      {
      if(!this.completed){
      _root.completedPuzzleCheck(); // add this to each of your pieces
      this.completed=true;
      }

      setProperty("piece8", _x,"456.4")
      setProperty("piece8", _y,"131.4")

      } else {
      if(this.completed){
      this.completed=false;
      _root.numCompleted--;
      }
      }
      }

      if(!numCompleted){
      numCompleted=1;
      } else {
      numCompleted++;
      }
      if(numCompleted==8){
      message.text="Great Job!";
      }

       

      stop();