Sim Programming with AS 3.0 part1: Vectors.
Simulation programming is what got me into Flash and keeps me into Flash. A lot of people work with Flash without ever actually doing any sim programming with it. Actionscript 2.0 was hacky and full of frustrating issues. I was considering the leap to Processing, but Actionscript 3.0 really whips the llamas ass.
Let me say a few things about the coolness and value of simulation programming. First it is cool because your code is not "explicitly" directing the operation of everything that happens in your program. Results are "random" and often quite unexpected. You don't write code to orchestrate every little thing. Instead you establish some groundrules and then say "go" and see what happens. It's quite amusing. If god is a clockworker that built the universe as a series of physical laws and then pushed "go" I can certainly relate. The universe is an ultimately cool simulation.
Secondly simulations and understanding how to build them provide insight into how to build recursive and search oriented algorithms. Simulations force you to break up your scenario into smaller similar chunks, then just define the differences between each chunk, parameterize those differences, and voila. A recursive search routine over a grid space, for example, actually shares a lot of the same properties. You are defining each "step" of your search from node to node over edges. You don't write code to try and define every single step, ad infinitum (which I see a lot from amateur interviewee's), but rather you write generic code that says what's going to happen at each step, and then you call that code over and over.
Pretty much always, there are lots of elements of your simulation that you will want to look "realistic", which means basically, to imitate real life. The best way to do that is often to reuse many of the same concepts used by physicists when trying to solve and model the real world...just reapply in simulation form. For starters, 3 incredibly important foundational concepts for the motion-based simulations I'll be discussing are "acceleration", "velocity", and "position". And for the math underlying all 3....we need vectors.
So for this post I'm going to start with my Vector class. This is a new endeavor and still a work in progress and I invite comments should any programmer happen to actually read this. You can get a copy of the full code file here: Vector
It supports it's own event dispatching, it's static events are shown at the top. It's public methods include add(), subtract(), normalize(), invert(), dotProduct(). It also has getters/setters for distance,length,x,y.
That's all I've got time for a.t.m. I need to work on this ;o)