3 posts tagged “actionscript”
When I was in highschool I wanted to be a newspaper journalist. When I graduated from college I wanted to be a school teacher. But at this point programming has clearly won out as my lifelong career.
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)
If you are developing anything from scratch, or maintaining anything relatively small, in Flash 8 or below, then please smack yourself.
I think we can all agree that code almost always ends up lasting longer than people anticipate. I still read stats that some 80% of production corporate code remains in COBOL or Fortran and other such craziness.
I also doubt there's any arguing at this point that flash 9 has reached at least 90% market penetration. This link shows 84% back in March, growing from only 55% in December '06. That's an incredible growth rate and it'd be impressive if since March it hadn't crept over 90.
Given that we know that code ends up lasting and hanging around longer than people anticipate, and flash 9 is being adopted at astonishing rates, continuing to generate code in Actionscript 2.0 at this point in time is not wise.
Flash 9 .swfs can be generated with only .as files and a command line compiler. No binary files are needed. So finally Flash can actually be incorporated into build cycles, placed in ant files, etc.
Actionscript 3.0 is also just a much much nicer language. No more hacks. Finally done right. The VM for it will be the background of Ecmascript 4.0, and has also been donated to mozilla to be synchronously developed as the VM for it's Javascript engine! (Link here).