Absolutely. Good MVC should be taught at birth. 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:17 AM, Beatrix Krümmer-Frau <[email protected]> wrote: > perfect! Can I use this for my Flash students? > > Am 16.02.2012 08:59, schrieb Ross Sclafani: >> From: Ross Sclafani<[email protected]> >> Date: February 16, 2012 2:39:34 AM EST >> To: Cor<[email protected]> >> Cc: Flash Coders List<[email protected]>, >> [email protected] >> 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 >> [email protected] >> http://chattyfig.figleaf.com/mailman/listinfo/flashcoders >> >> > _______________________________________________ > Flashcoders mailing list > [email protected] > http://chattyfig.figleaf.com/mailman/listinfo/flashcoders _______________________________________________ Flashcoders mailing list [email protected] http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

