3 Replies Latest reply on Sep 9, 2011 12:44 PM by kglad

    AS1 / 2 Jigsaw puzzle pieces - positions

    eggboyuk

      Hi and sorry this is a long one, but please bear with it - I think it should be simple.

       

      I have a jigsaw that I'm back engineering to suit my needs. The jigsaw's default is to place the pieces in a random order on the stage, and then when you drag and drop the pieces into the puzzle area, they either click in place (if placed in the right area), or spring back to a random position on the stage, until you get the puzzle right. I need to just adjust this a little. I want the puzzle instances to appear in a defined position on the stage (think I've cracked this OK), but also when the user places the piece in the wrong position I want the piece to spring back to that exact same position it was in. This is the bit I can't resolve. Here are some script snippets which I hope will shed light on this.

       

      I'm defining the position of the pieces on the stage like this:

       

       

      p2._x = -380;

      p2._y = 70;

       

       

      p2 being the instance name of one jigsaw piece. This bit of script being in the timeline of the movie clip that contains the puzzle pieces:

       

      Then in a separate external AS file, the original author has defined the following rule if the piece is not dragged to the correct spot.

       

       

      else

      {

      this._x = Math.random()*180;

      this._y = Math.random()*200;

      snd = new Sound();

      snd.attachSound("snd_fault");

      snd.start();

      }

      }

       

       

      The jigsaw pieces reference the external script with a simple:  #include "ascript.as"

       

      this. defining the individual jigsaw piece that's currently being interacted with (I guess). You can see this syntax applies a random positioning to the piece. How can I adjust this to make it move the piece in question back to it's original position when placed in the wrong area?

       

      The original FLA file and script can be downloaded here:

       

      http://www.actionscript.org/resources/articles/13/1/Jigsaw-Puzzle/Page1.html

       

      Any help on this would hugely appreciated. Thanks in advance.

       

      Ed.