I have a fuller framework that details a view life cycle, subModels, a Controller tree, animated transitions on change() and more. The classes I wrote are just the simplest examples that I thought would get people started. I'll get the framework polished up and open sourced to Github if you guys are interested
Ross P. Sclafani Owner / Creative Director Neuromantic Industries http://www.neuromantic.com http://ross.sclafani.net http://www.twitter.com/rosssclafani 347.204.5714 On Feb 16, 2012, at 5:46 AM, Paul Andrews <p...@ipauland.com> wrote: > Excellent job. > > I have one small point, on a practical level. > > For the views, in particular, I don't usually pass arguments to the > constructor. It's not such a big deal for code-only examples, but in my flash > world I mix my components between stuff created dynamically and things > created in the IDE - sometimes I build components as assemblies on the stage > using the IDE. The point is that passing arguments to the constructor then > becomes an issue for a view. > > Might I suggest an init() function to pass in Model and Controller? > > Paul > > > > On 16/02/2012 07:59, Ross Sclafani wrote: >> From: Ross Sclafani<ross.sclaf...@gmail.com> >> Date: February 16, 2012 2:39:34 AM EST >> To: Cor<c...@chello.nl> >> Cc: Flash Coders List<flashcoders@chattyfig.figleaf.com>, >> flashcoder...@googlegroups.com >> Subject: Re: MVC >> >> feel free to hit me up any time ill try to have time to respong >> >> none the less, this should get you started: >> >> /* >> * Model.as >> * >> * mvc.Model; >> */ >> package mvc { >> import flash.events.EventDispatcher; >> import flash.events.Event; >> class Model extends EventDispatcher{ >> private var _count:int = 0; >> public function get count():int{ >> return _count; >> } >> public function set count(value:int):void{ >> this._count= value; >> update(); >> } >> public function Model(){ >> super() >> } >> private function update():void{ >> this.dispatchEvent(new Event(Event.CHANGE)); >> } >> } >> } >> >> >> /* >> * Controller.as >> * >> * mvc.Controller; >> */ >> package mvc { >> public class Controller { >> private var model:Model; >> public function Controller(model:Model){ >> super() >> this.model = model; >> } >> public function countUp():void{ >> this.model.count++; >> } >> } >> } >> >> /* >> * View.as >> * >> * mvc.View; >> */ >> package mvc { >> import flash.text.TextField; >> import flash.events.Event; >> import flash.display.Sprite; >> public class View extends Sprite(){ >> private var model:Model; >> private var controller Controller; >> private var textField:TextField = new TextField(); >> public function View(model:Model, controller:Controller){ >> model.addEventListener(Event.CHANGE, this.model_changeHandler); >> super() >> this.model = model; >> this.controller = controller; >> this.addChild(this.textField); >> this.stage.addEventListener(MouseEvent.CLICK, >> this.stage_clickHandler) >> >> } >> private function stage_clickHandler(event:MouseEvent):void{ >> this.controller.countUp(); >> } >> private function model_changeHandler(event:Event):void{ >> this.textField.text = this.model.count >> } >> } >> } >> /* >> * App.as >> * >> * MVC screen click counter. >> */ >> package{ >> import mvc.Model; >> import mvc. View; >> import mvc.Controller; >> public class App{ >> private var model:Model = new Model(); >> private var controller:Controller = new Controller(this.model); >> private var view:View = new View(model, controller); >> public function App(){ >> this.addChild(this.view); >> } >> } >> } >> >> Now imagine a Model with more properties. >> And tons of different Views of them that data. >> Some of which provide a UI linked to Controller methods that manipulate it. >> >> _ross >> >> >> _______________________________________________ >> Flashcoders mailing list >> Flashcoders@chattyfig.figleaf.com >> http://chattyfig.figleaf.com/mailman/listinfo/flashcoders >> > > _______________________________________________ > Flashcoders mailing list > Flashcoders@chattyfig.figleaf.com > http://chattyfig.figleaf.com/mailman/listinfo/flashcoders _______________________________________________ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders