Posted: January 31st, 2010 | Filed under: AS3, Design Patterns, Flash | No Comments »
It’s nice to have a simplified version of an MVC architecture to start a new project with. Those familiar with MVC (Model, View, Controller) know that it’s a very scalable architecture and a great way to separate your data from the visual assets of your site, then allow the controller to interface between the two. Those unfamiliar will enjoy how well it allows the data, logic and view to work with each other in an encapsulated way.
The framework operates in a cyclical way: View > Controller > Model > View.
Here, the View has an event listener waiting for a button to be clicked. This listener calls a function in the controller. Depending on the logic in the controller, the method sends a property to the Model. Upon receiving that property the Model dispatches an event that the View is listening for. The View then initiates an action.
In this example, buttons, the text box and the red bar exist in the View. The event listener in the View waits for a button to be clicked and then executes a method in the Contoller. The Controller performs simple logic with the data it’s received. Here it tests if the number is between 0 and 10. If is does, then set a property in the Model. The Model then dispatches an event that the View is listening for. The View executes code which changes the width of the bar.
Leave a Reply