- as much as is possible, put all code in classes
- avoid the temptation to place non-trivial code on frames, clips, and buttons
- if you want to put code on something, that's a sign that it needs to be integrated into your application's architecture
- keep each class in a separate .as file
- in your movie, use
#include to load each class
- remember, a class is just:
- a bunch of properties
- a bunch of methods
- a constructor
- keep the above items separate! as follows:
- assign all instance properties to YourClass.prototype
- assign all instance methods to YourClass.prototype.
- assign all static class properties to YourClass.
- assign all static class methods to YourClass.
- in the constructor, ONLY do initialization -- don't put any other code there
- for example, here's the stripped down source for a MessageDialog class
// CLASS MessageDialog EXTENDS MovieClip
MessageDialog = function () {
}
// SET SUPERCLASS
MessageDialog.prototype = new MovieClip();
// PROPERTIES
MessageDialog.prototype.msg_txt = null;
MessageDialog.prototype.title_txt = null;
MessageDialog.prototype.titleBar_mc = null;
MessageDialog.prototype.ok_btn;
MessageDialog.prototype.close_btn;
// METHODS
MessageDialog.prototype.init = function (title, message, x, y) {
}
MessageDialog.prototype.dragDialog = function () {
}
MessageDialog.prototype.dropDialog = function () {
}
MessageDialog.prototype.closeDialog = function () {
}