Associated classes in Flash MX 2004
I've been developing a great deal in Flash lately, due to the fact that the product I'm working on has a lot of graphical requirements.
I'm not a deseloper (designer/developer) yet, but I can at least develop the functionality that I need.
As a primarily .Net coder, I like to put my logic into neat classes, trying to harness OOP as much as possible. Working with Flash, you have a few choices of where to put your code:
- You can put it into the symbol instances itself, meaning each instance you use will have to be provided with the code
- You can put it into nested symbols (symbols contained within a symbol), which allows you to have the same code and events on every instance you create of this symbol
- You can even put it on a frame in a layer's timeline - I try to steer clear of this, but it probably depends on what kind of app your developing
- Another way of organizing your code is to put it into class files. Your symbol code can then call the code in these class files, as long as the class files are in the same directory
- And then the best way (for my kind of app) is to use the associated class functionality. You can go the full monty and make your symbol a component is you want to, but for my use I haven't needed this yet.
The last option associates a class with the symbol, allowing you to put your code into a neat class, and in it's instance methods reference the symbol instance with this.
You don't need to write a full scaled component to achieve this, only associate your symbol with your correctly defined class file, right click the symbol in the library and point it to the created .as file.
The info about creating components in the Flash help file shows you how to structure your class' file and where to put it, etc.
Here's a real complete (a bit too fleshy) tutorial on creating components: http://www.flashcomponents.net/tutorials/triangle/triangle.html