While Actionscript is growing, you should control your applications in the aspect of software engineering. So, please use design patterns! Today I will write about one of the fundamental design pattern. My focus will be on AS2 but you may see similar example on AS3 too.

MVC Design Pattern

MVC pattern is one of the well known techniuqe to code. In antient times of computer coding, computer programs had very limited user and client interfaces. The increased richness of the user interface presents new challenges, and the Model View Controller (or MVC) pattern addresses those challenges to help create more flexible applications. Flash is a good and fast solutions to create GUI based applications. So, why not use MVC in our samples?

MVC pattern idea bases on that data and view located in seperate logics. There are many disadvantages for the oppsite aim – data and view are together.

These are :

• Difficult management of data from outside the object
• Creating different GUIs with the same logic
• Difficult modification of GUI

Understanding the Pattern

MVC pattern is based on three layers: Model, View and Controller. Each has its own responsibilities.

Locates all data information for the application. It does not care about how you interpret it or how process it.

View displays the information coming from the model. It only cares the GUI part and listens Model for data updates.

Controller is a subsystem between Model and View. It helps both to communicate each other. For example, It updates data according to the action recieved from  View.

After learning all basic idea, let’s see an example. I created a simple slot machine example with MVC. First we will look at the data model.