View Full Version : have a fuction rotate an object
big20oz
02-25-2004, 02:24 PM
OK I have a button and a star on the stage. I want the star to spin a for a couple seconds when you press the button. I have the following code on the first frame 1st layer.
X=0;
function runMe()
{
while(x<100){
_root.star._rotation += 10;
x++;
}
}
Now on the button I have the folllowing code
on (press) {
runMe();
}
I would think this would work but it isn't the star just sits there.
Any ideas?
binkyboo
02-25-2004, 03:45 PM
x = 0;
function runMe() {
if (x<100) {
_root.star._rotation += 10;
x++;
} else {
clearInterval(myInterval);
}
}
myInterval = setInterval(runMe, 100);
Your code runs but it loops to 100 so fast that the star become static so quickly. Try playing with setInterval. Work from my example if you'd like.
big20oz
02-26-2004, 12:11 PM
Working with that code I've got it working but I can't get it to play more then once... I know that x is being set to 100 and so when I hit the button a 2nd time the condition is already met meaning no run. So what is a good way code-wise to reset the x? I've been trying for like 3 hrs.
binkyboo
02-26-2004, 12:20 PM
on (release) {
clearInterval(myInterval);
x=0
myInterval = setInterval(runMe, 20);
}
divarch
02-27-2004, 04:07 AM
If U need it to play more than once, why do U need 100 in your 'if' condition?
What is that for?
If you want it to play indefinately, then:
function runMe() {
root.star._rotation += 10;
}
myInterval = setInterval(runMe, 100);
Cheers
|
vBulletin® v3.8.4, Copyright ©2000-2009, Jelsoft Enterprises Ltd.