Recently, I've been asked a lot about creating applications by writing code in an FLA file vs. creating them using classes and
Object Oriented Programming. Making the decision can sometimes be tough, especially to those who are new to programming. Usually, it's hard for people new to programming to justify doing the work to create classes. Honestly, I use a lot of classes and FLA code. So, why choose either one when building an application?
OOP is a beautiful thing. Let me give an example of OOP in action. In order to create a music player using
ActionScript 3.0, you need an instance of the Sound class to load and play the sound, an instance of the SoundChannel class to stop/pause/seek, and an instance of the SoundTransform class to control the sound's volume. Using OOP, I can make one class that connects all three. I could do that in an FLA file, but I'd have to rewrite or copy/paste the code every time, which takes time. Now, what if I wanted to add more functionality to every media player application I created? To do that, I'd have to add it to each FLA file. Using OOP, I simply update my EasySound class. Further, I can give my EasySound class methods that control all aspects of the sound (play,stop,pause,resume,seek,setVolume,etc.) and control the sound entirely from one instance. How cool is
that!?
Pretty much the only thing that's not cool about OOP is that though OOP is better for reuse in the long run, it's initially more time consuming. For that reason, I'm not the biggest fan of document classes that I'm only going to use once.
At the same time, I'm a huge fan of making quick prototypes in FLA files. This enables me to rapidly create variables and functions for an app without having to create an entire class file. If I'm creating some sort of prototype, or teaching a programming idea, I prefer to go with an FLA and not create the class files.
The reason I stick to FLA files mostly for prototypes is because of the cons of using FLA files for major applications. One con is that FLA files don't contain searchable text, as ActionScript files do. Leveraging the power of my operating system (now Mac OS 10.5- whoot!), I can quickly search through thousands of class files to look for methods or comments that describe what the class does. Another con is reuse. Instead of redefining a function, or copying and pasting the function from one FLA to another, I simply import the class I created and run the method.
Moral of the story- I say to use FLA files for prototyping but to create classes for major applications, especially any applications where you would consider reusing code. If the time it takes to write code is an issue, you might want to consider writing code using Flex. Flex gives you case insensitive code hinting for everything, even your custom classes.
What methods do you use when creating applications? Do you prefer FLA or OOP?