Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

for loop, whats wrong?

Status
Not open for further replies.

styleBunny

Technical User
Jun 20, 2002
133
AU
im a bit rusty at flash, so here goes.

on (release) {
for (x=0; x<5 ; x=x+1) {
_root.ball._x = random(500);
_root.ball._y = random(400);
}
}

i want to use this loop so that my ball movie does 5 random location changes then stops, at the moment it does 1 random for each click, and doesnt stop at 5. plz help :)

p.
 
It's doing it alright, just displayed too fast for you to see! Maybe stick in a pause in your loop!

Regards,

cubalibre2.gif
 
lol, is there is a pause command that i can insert into this loop?
 
Hold on... Got to test this! Not as fast as my instrutor hero Bill!

Regards,

cubalibre2.gif
 
This seems to work fine...

Code:
on (release) {
	wait = setInterval(pause,2000); // 2 seconds
	function pause(){
		x++;
		_root.ball._x = random(500);
    	_root.ball._y = random(400);
		if (x >= 5){
			clearInterval(wait);
			x = 0;
		}
	};
}

You can change the pause, by changing the 2000. 5000 would be 5 seconds.
If you count the initial position of the ball, that would make 6 positions total. You can reduce the if statement... if (x >= 5){... down to 4 to have 5 different positions. Or you could set the ball off-stage to start with, thus the first position not visible.



Regards,

cubalibre2.gif
 
like a dream!

thanks oldnewbs, thanks hero bill!
:)


p.
 
i notice now that if you double click, the loop goes a little haywire and keeps on repeating.

could this becaused by the type of loop being used?

p.
 
this works.

on (release) {
wait = setInterval(pause, 40);
// waits 0.4 seconds
function pause() {
for (y=0; y<5; y++) {
_root.slider2._x = random(_root.targX+150);
_root.slider2._alpha = random(50);
_root.slider._x = random(_root.targX+150);
_root.slider_alpha = random(50);
clearInterval(wait);
}
_root.slider2._alpha = 20;
}
}

hi-5 anyone?
p.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top