AS 2.0 MCVC Template
December 25th, 2007
For the past year I have been building most of my AS 2.0 applications on top of a standard class template system I developed called MCVC. I thought it would be nice to share it with everyone now that I have moved over to AS 3.0. To my surprise there are still a great deal of developers using AS 2 so I hope this is helpful. I do have to warn you that this is a small complex system of 4 class templates to help you rapidly build applications off of. In order to leverage its speed and functionality you have to follow the system exactly. This is not for everyone
MCVC stands for Model, Controller, View, Component. It is an adaptation of the MVC design pattern. By taking some of the best concepts in MVC and altering it to work a little easier in AS 2.0, I developed the following class templates. I will explain the system in a little more detail over several posts but this is a basic background on the concept and a good lead into it’s usage.
This is kind of a framework but it is better to think of it as a set of template classes to build upon. Here is an explanation of the core classes and there role:
- BaseModel (MCVC) This is the data class of an application. In this system it represents a core data class with no visual representation. All data classes are extended from this class and are responsible for loading xml data, parsing that data, managing the data/state of the supporting classes (such as Views and Components) and handling the receive/sending of events through the controller binding.
- BaseController (MCVC) This class is a singleton class the facilitates passing events between binded views and models as well as other models registered with the class. All models by default register them self with the class so when an event is sent, you simply use the receiving model’s ID to send the event object.
- BaseView (MCVC) The view represents the visual representation of a model. It handles graphic state changes, redrawing of the display, and loading of external visual resources (such as images and other swfs).
- BaseComponent (MCVC) This class is a combination of a Model and a View. It represents library linkage assets and handles a few of the issues in Flash where you would need to closely couple your Model data with a View’s display.
There is also one extra class that helps the system but is optional:
- BaseApplication extends the model and offers some extra methods for building an application core class. It handles loading/parsing of a config xml, loading/parsing of view coordinates (for external layout from xml), and general stage configuration.
Looks like there is a lot to go over so in the next few posts I will go over each class template in detail and finally wrap this up with a sample application to illustrate best practices. I was thinking of porting this system over to AS 3 but for the time I am still trying to figure out if its even worth it. This solved a lot of problems I had in AS 2 like how to cleanly and quickly broadcast events between classes without using native AS events, the Delegate Class, Global or Root as well as define a set structure that all of my code could follow. At the time I was playing with Ruby on Rails and cakePHP so I tried to take a few concepts from those frameworks as well. Unfortunately not much translates over.
As with all of my code there is always room for improvement so please send in some comments or feedback. I would be more then happy to help anyone set this up for themselves. I have tried to comment these classes with as much detail as possible and I even left in a lot of my deprecated methods in so you could see how the system evolved while I worked with it.











April 23rd, 2008 at 11:18 pm
[...] I have been building a new Framework at Heavy. This framework is more designed oriented then the MCVCframework I was using before. The entire UI (Display) tier is built on XML similar to MXML. With [...]