View Full Version : question about Classes

11-29-2008, 02:27 AM
Hey guys, I'm fairly new to actionscript, I made a few games in Flash CS3 using AS 2.0, but 3.0 seems to be a whole new deal. I'm more familiar with c++ than I am with actionscript.

Anyways, I'm working with Flash Develop, and I have a question about classes. In my practice project, I have a ball class, and the application class. The application class creates some number of balls, and the ball class directs the balls to crowd around the mouse and bounce off the edges of the screen. My question is how would I add collision with other instances of the ball, or even just other objects that I add in later? ( platforms.. etc) Is there some way to refer to other instances of the ball class from within it's own class?

My code structure looks something like this:
Application class
Create Balls

Ball Class
Move Ball
Collide with screen edges

Thanks in advance :)

12-01-2008, 10:17 AM
It might make your life easier if you handled the ball animations from the Application Class rather than from the Ball Class.

The ball objects just need to hold variables that Application can access and change, such as currentSpeed.

Then you just need one enterFrame function in Application that loops through an array of all of your balls and animates them. Something like ballsArray[i].x += ballsArray[i].currentSpeed.

With this method you have access to all of your balls in a central location (Application).

12-02-2008, 02:52 AM
Thanks, that sounds like an excellent plan :)