4 Replies Latest reply on May 19, 2009 3:21 PM by learner102

    Finishing Action Script

    learner102 Level 1

      This is my first time posting to a Forum.  I am a graphic designer by nature and not a coder (so i may not be clear).  I usually find the AS i am looking for by Googling and "borrowing" bits and pieces of code to fit my personal needs for Flash movies.  Can't figure it out this time.  I have a 'drag and snap to' jigsaw puzzle Flash game.  Works great (in my opinion) but I can't figure out how to have the code display a "Great Job!" message in a dynamic text box when all pieces are at their setProperty _x & _y coordinates.  Any help would be GREATLY appreciated.  Again i am new at forums.  Please let me know if i need to send the .fla or paste the AS into a reply message.  Thank you.

        • 1. Re: Finishing Action Script
          kglad Adobe Community Professional & MVP

          is there some actionscript that executes when a piece is dropped onto the correct spot (and it's then aligned exactly)?  if so, increment a variable (that's intialized at zero) each time that occurs and check if the variable's value == total puzzle pieces.  if yes, display your message:

           

          yourTextField.text = "Great Job!";

          • 2. Re: Finishing Action Script
            learner102 Level 1

            Yes, the pieces of the puzzle are buttons with the following AS attached to them:

             

            on (press)
            {
            startDrag("piece8");

            }
            on (release)
            {
            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!
            {
            setProperty("piece8", _x,"456.4")
            setProperty("piece8", _y,"131.4")
            }
            }

             

            There are 8 pieces.  The following script is attached to the frame in an Actions layer:

             

            Button.prototype.swapDepths = MovieClip.prototype.swapDepths;
            TextField.prototype.swapDepths = MovieClip.prototype.swapDepths;
            Button.prototype.removeButton = MovieClip.prototype.removeMovieClip;
            // TextField already has removeTextField

            piece1.onPress = function () {
            piece1.swapDepths(-1000);
            };
            piece2.onPress = function () {
            piece2.swapDepths(-1000);
            };
            piece3.onPress = function () {
            piece3.swapDepths(-1000);
            };
            piece4.onPress = function () {
            piece4.swapDepths(-1000);
            };
            piece5.onPress = function () {
            piece5.swapDepths(-1000);
            };
            piece6.onPress = function () {
            piece6.swapDepths(-1000);
            };
            piece7.onPress = function () {
            piece7.swapDepths(-1000);
            };
            piece8.onPress = function () {
            piece8.swapDepths(-1000);
            };


            if ((piece1._x==346.6&&piece1._y==189.8))
            {
            message.text="Great Job!";
            }

            stop();

             

             

            The last part is where i have a dynamic text box with an instance name of 'message'  similar to your reply.  Hopefully you can look at the code above and tell me what i did wrong.  Thanks for replying.

            • 3. Re: Finishing Action Script
              kglad Adobe Community Professional & MVP
              use:

               

              on (press)
              {
              startDrag("piece8");

              }
              on (release)
              {
              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!
              {

              _root.completedPuzzleCheck(); // add this to each of your pieces
              setProperty("piece8", _x,"456.4")
              setProperty("piece8", _y,"131.4")
              }
              }

               

              There are 8 pieces.  The following script is attached to the frame in an Actions layer:

               

              function completedPuzzleCheck(){   // add this to your main timeline

              if(!numCompleted){

              numCompleted=1;

              } else {

              numCompleted++;

              }

              if(numCompleted==8){

              message.text="Great Job!";

              }

              }

               

               

              Button.prototype.swapDepths = MovieClip.prototype.swapDepths;
              TextField.prototype.swapDepths = MovieClip.prototype.swapDepths;
              Button.prototype.removeButton = MovieClip.prototype.removeMovieClip;
              // TextField already has removeTextField

              piece1.onPress = function () {
              piece1.swapDepths(-1000);
              };
              piece2.onPress = function () {
              piece2.swapDepths(-1000);
              };
              piece3.onPress = function () {
              piece3.swapDepths(-1000);
              };
              piece4.onPress = function () {
              piece4.swapDepths(-1000);
              };
              piece5.onPress = function () {
              piece5.swapDepths(-1000);
              };
              piece6.onPress = function () {
              piece6.swapDepths(-1000);
              };
              piece7.onPress = function () {
              piece7.swapDepths(-1000);
              };
              piece8.onPress = function () {
              piece8.swapDepths(-1000);
              };


              stop();

               

               

              The last part is where i have a dynamic text box with an instance name of 'message'  similar to your reply.  Hopefully you can look at the code above and tell me what i did wrong.  Thanks for replying.

              • 4. Re: Finishing Action Script
                learner102 Level 1

                Thank you, thank you, thank you!  It worked perfectly.  There is a lot I need to understand about AS and thanks to you (and others like you) forums do work as a way to help those in need.