The Model-View-Controller Design Pattern in Actionscript 3
http://en.wikipedia.org/wiki/Model_view_controller
The MVC Design Pattern
- Creates a separation of Class roles
- Adds a clear and logical communication structure
- Increases flexibility in larger applications
Model
Handles data storage and retrieval (eg. Store character x position)
View
Handles the display/communication (eg. Position character on stage)
Controller
Handles most the of the application logic (eg. Get current x position)
MVC – basic structure
Each model can have multiple views
Each view has at least one matching controller
Creates a separation between form, content and action
The model becomes the base of the application
Communication Model
MVC planning example - Pacman Game
Here is a simple application to show MVC in action
Application abstract:
A circle which changes colour randomly every time a button is pressed
Designing the simple application
Broken down into the MVC pattern this would look like:
Download a basic Actionscript 3 MVC example that shows how to move an object around the stage using the keyboard.
Download a basic Actionscript 3 MVC example that shows how to load and display text stored in an external text file.
Download the MVC circle example discussed in the tutorial.
For more on the Model View Controller and other Design Patterns in Actionscript 3 check out 'Actionscript 3 Design Patterns' by William Sanders and Chandima Cumaranatunge.
:))
Trả lờiXóa;;)
=))
:0]