View Full Version : How do I rotate a jigsaw puzzle piece?
Bruce
October 24th, 2004, 04:37 AM
Hi all,
I am new to action script and haven't been able to find any reference as to how to rotate individual jigsaw puzzle pieces using the left and right arrow keys. Can anyone help? Here is the action script that I am using:
on (press) {
startDrag("_root.pic9", true);
this.swapDepths(100);
}
on (release) {
stopDrag();
if (this._droptarget == "/target9") {
setProperty(this, _x, 498.9);
setProperty(this, _y, 312.8);
} else {
setProperty(this, _x, 54.1);
setProperty(this, _y, 88.9);
}
}
Thanks,
Bruce
Smee
October 24th, 2004, 02:14 PM
on (keyPress "<Left>") {
setProperty(this, _rotation, this._rotation-90);
}
on (keyPress "<Right>") {
setProperty(this, _rotation, this._rotation+90);
}
or
on (keyPress "<Left>") {
this._rotation -= 90;
}
on (keyPress "<Right>") {
this._rotation += 90;
}
Bruce
October 25th, 2004, 04:27 AM
Thanks Smee,
This worked well for the first jigsaw puzzle piece (with the 'rotate piece' action script on the first line). I have since entered the suggested script to all the other jigsaw pieces, but now find that the left and right arrow keys rotate the incorrect pieces. I have tried 'slotting' in the script (to rotate the pieces) into various places but am still encountering problems. I am obviously not entering it in the correct place or format. Here is the new amended action script:
on (keyPress "<Left>") {
setProperty(this, _rotation, this._rotation-90);
}
on (keyPress "<Right>") {
setProperty(this, _rotation, this._rotation+90);
}
on (press) {
startDrag("_root.pic9", true);
this.swapDepths(100);
}
on (release) {
stopDrag();
if (this._droptarget == "/target9") {
setProperty(this, _x, 498.9);
setProperty(this, _y, 312.8);
} else {
setProperty(this, _x, 54.1);
setProperty(this, _y, 88.9);
}
}
Thanks,
Bruce
Smee
October 25th, 2004, 06:48 PM
on (keyPress "<Left>") {
if(beingDragged){
setProperty(this, _rotation, this._rotation-90);
}
}
on (keyPress "<Right>") {
if(beingDragged){
setProperty(this, _rotation, this._rotation+90);
}
}
on (press) {
startDrag("_root.pic9", true);
beingDragged = true;
this.swapDepths(100);
}
on (release) {
stopDrag();
beingDragged = false;
if (this._droptarget == "/target9") {
setProperty(this, _x, 498.9);
setProperty(this, _y, 312.8);
} else {
setProperty(this, _x, 54.1);
setProperty(this, _y, 88.9);
}
}
Bruce
October 26th, 2004, 06:42 PM
Hi Smee,
Thanks for all your help!!
I am still having the same problem except that while "on drag" another jigsaw piece will rotate when the arrow key is pressed. It seems that the actionscript needs a code to isolate the piece that I am working with from the others. Each puzzle piece(movie clip) has an instance name - should I include this name somewhere?
Thanks,
Bruce
Smee
October 26th, 2004, 10:12 PM
The beingDragged variable I added should do that exact thing.. I'm not sure how you have this set up, any chance of a fla file?
Bruce
October 27th, 2004, 07:16 AM
Hi Smee,
Thanks for offering to check my fla file!
I tried sending it but it was much too large a file. I then made a small 4-piece puzzle with the same actionscript, etc. but even that was above the "Kirupa limit" and would not attach!!
I will have to just keep on working on it and hopefully will find a solution.
Thanks,
Bruce
Smee
October 27th, 2004, 02:31 PM
Try changing the beingDragged variable name to beingDragged9, and the rest to whatever number you use for those pieces.
Powered by vBulletin® Version 4.1.10 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.