Skip to main content
Participating Frequently
April 13, 2007
Question

Random Moving Circles

  • April 13, 2007
  • 3 replies
  • 428 views
I am trying animate the image in the supplied link.

Basically I want a bunch of circles to move around randomly inside a box. I think I'd also like them to bounce of the edges of the box so that they are moving in all directions.

The circles will be different sizes so I'm not sure if I need to apply code to each circle size or if there is a scripting way to create randomly sized circles.

Can anyone help me out, or point me in the direction of a good tutorial. I've been animating in Flash for a while but just begining with action script.

Thanks!
sample image
This topic has been closed for replies.

3 replies

kglad
Community Expert
Community Expert
April 16, 2007
only the box movieclips are onstage to form the border encasing the balls. you can set their _alpha to 0 if you don't want them visible.

but you need a ball moviecip with a LINKAGE ID = ballID. remove the ball movieclip from the stage, find it in the library, right click it, click linkage, tick export for actionscript and in the linkage id box type: ballID, then click ok and retest.
kglad
Community Expert
Community Expert
April 13, 2007
it would make it easier but i already have an experiment that i created where the circles (more like billiard balls) bounce off each other and the table edges.

i have it on my home computer so i'll check it in a few hours when i get home.
kglad
Community Expert
Community Expert
April 15, 2007
here's the code with balls bouncing off each other. i used four movieclips boxleft, boxright, boxtop, boxbottom to form a rectangular border and there's a ball movieclip with linkage id = ballID

Matt-RAuthor
Participating Frequently
April 16, 2007
Thanks for the code!
However I tried it and it's not working yet. I think it probably has something to do with the Movie Clips I created.

Just to clarify, the things I need to add are:
- a ball MC called ballMC
- four MCs called boxleft, boxright, boxtop, boxbottom

Should I place all these MCs on the stage?
What are the names I should give each MC instance?

Hope this makes sense.
Thanks.
kglad
Community Expert
Community Expert
April 13, 2007
will the circles bounce off each other, too?
Matt-RAuthor
Participating Frequently
April 13, 2007
No the circles don'l need to bounce off each other.
Hope that makes it easier.