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.
this._x = Math.random()*180;
this._y = Math.random()*200;
snd = new Sound();
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:
Any help on this would hugely appreciated. Thanks in advance.
assign the original position of each piece as a piece property when you app initializes.
Hi. Thanks for the swift reponse. Where would I apply this script and how does that impact on the random 'springing back' positioning of the pieces when dragged to the wrong area of the puzzle. I need them to spring back but to their original positions. What should I do with the 'else' snippet of script that the original author has generated in the external AS file?
you assign those properties when your app initializes.
and you apply your tween to snap back when a piece is dropped in the wrong location.