Brent Gore wrote:
Ok, so I've read a lot about design patterns but have yet to really
implement them. Reading = easy. Doing = hard. :0
My first question is, is it typical to create Composite MVC's (or nested
MVC patterns?) throughout the application?  To illustrate: Let's say an
app has a pop-up window, which has a window box, a text area, and a
button.  Each of these implements the MVC pattern internally.  The
pop-up window itself implements MVC, and perhaps all three implement a
composite interface.  Would this architecture be typical and/or
"correct"?

The next question; if the above is correct then how do you connect them,
especially in a Flash environment?  Continuing the example, when the
window-model is instantiated, it calls an attachmovie to WindowView,
which is an MC in the library and has a corresponding WindowView class.
So... ok now what?  WindowModel instantiates new instances of Button and
TextArea (calling their model-classes)?  Is the Model the entry point
for an MVC pattern?  Then Button and TextArea take the WindowView inst
as a param, and attach their views to it?

This is where I really start to pull my hair out because there are so
many options.  I think the above would work, but I'm not really sure if
that's using MVC correctly.

Sorry for the super-long question, and thanks for your help!!!

Best,
Brent
_______________________________________________
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders




I just recently read _Head First Design Patterns_ which was an awesome book and I highly recommend it. All of the examples are written for Java but I was able to convert them all to AS2 very easily. I was able to convert and compile every example I think.

// Java
public int add (int x, int y) {
        return x + y;
}

// AS 2.0
public function add (x:Number, y:Number):Number {
        return x + y;
}

Another book I read that covered MVC with Flash is Moock's _Essential ActionScript 2.0_. Also, a good book.

I recently finished my first MVC Flash app and those two books were very helpful. However, I did more of a MVC and Delegation Event Model hybrid.

The way I handled my views was to design movie clips visually and place them on the stage where I wanted and gave it an instance name. I then created a controller class and pass to it the instance name of the movie clip I want to control. I've tried building the view completely by the controller with AS createEmptyMovieClip and such but was wasting too much time not being able to see anything at design time. Pre-building the mc and placing it on the stage both gave me instant visual feedback and prevented the neccessity of a linkage name and having to export the clip before frame 1 making my preloader more accurate.

// The View
// view_mc is a movie clip on the stage with said instance name.

// The Model
var oModel:MyModel = new MyModel();

// The Controller
// composites both the model and the view
// this way I can control how they both behave.
var oController:MyController = new MyController( oModel, view_mc );

// Add the controller as a listener to the Model's events
oModel.addListener( oController );

// Start the Model
// with a 15 second interval of requesting new data
oModel.start( 15 );

I chose not to pass event objects but rather fire a generic onUpdate() event on each listener. Inside oController.onUpdate() I request the info I need from the composited oModel and pass that info along to the composited view_mc. This allowed me to have different views listening to the model and each requesting only the info they needed instead of getting all-or-nothing. When my model's data changed, it all changed but all of it's listening views didn't need all of the data.


The ARP framework that Mike mentions looks good too. I used MX Forms on another project and ARP would have been nice in that case.


JOR


___________________________________
===  James O'Reilly
===
===  SynergyMedia, Inc.
===  www.synergymedia.net

_______________________________________________
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Reply via email to