Many of you have been waiting patiently for this post, and let me say that I have worked many hours to get this where it is today. I wanted to get my code to the point where it was solid enough that I would actually publish something with it, and I believe it is there. Thanks to those who have encouraged me to finish this post, and I look forward to seeing how it is used!
In introduction, let me say a few things about this post: first, I have tried to alter my scope slightly in order to be more accessible to readers who may not have access to a full licensed copy of Flash. So, to help with that and make these lessons more accessible, I have decided to write them in such a way as to be compiled by the Flex SDK, a fully open source framework to allow anyone to build robust Flash applications. I prefer to use the full Flex Developer 3 for development and release, but even without it, you can compile full AS3 or Flex applications using only the SDK from the command line. One other major benefit to doing my development with Flex Builder is the ability to publish my source code for all to view online as well as download.
Obviously, this opens up the accessibility to a much broader range of individuals looking to learn Actionscript 3 or Flex. So, all this to say that the code in this post, while doing practically the same thing as the previous posts (and keeping the majority of the same logic), cleans up a ton of structural issues to lend itself more cleanly towards a completed project. That being said, we are simply focusing on the Tower object itself this time. I will leave it to your imagination and time to read through the rest of the cleaned – and fully documented, I might add – code. I may find time to write some more generalized posts on the Flex framework itself in days to come, but for now, suffice to say that the main file that is compiled as the application (in our case, called “MagicTD.as”) will be instantiated as the main() function and will serve as our entire platform base. You will notice on line 12 of this file all the variables needed to set up our SWF with the desired dimensions, background color and framerate.
So, without further ado, let’s jump right into our Tower class.
Continue reading