Re: [Flashcoders] Fwd: MVC

2012-02-17 Thread Peter Ginneberge



Main problem that I see with the code that was posted is that it breaks
a major MVC rule and teaches a real bad habit: Views shouldn't have any
knowledge of Models


Not sure where you get the idea that a View shouldn't communictate with the 
Model directly:

This states otherwise: 
http://st-www.cs.illinois.edu/users/smarch/st-docs/mvc.html

quote
Unlike the model, which may be loosely connected to multiple MVC triads, Each view is associated with a unique controller and vice 
versa. Instance variables in each maintain this tight coupling. A view's instance variable controller points at its controller, and 
a controller's instance variable view points at its associated view. And, because both must communicate with their model, each has 
an instance variable model which points to the model object. So, although the model is limited to sending self changed:, both the 
view and the controller can send messages directly to each other and to their model.

/quote

For those wondering why I quote the above article:
http://en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%93controller#History

regards,
Muzak


- Original Message - 
From: jchilc...@interactivityunlimited.com

To: Flash Coders List flashcoders@chattyfig.figleaf.com
Sent: Thursday, February 16, 2012 3:07 PM
Subject: RE: [Flashcoders] Fwd: MVC



Main problem that I see with the code that was posted is that it breaks
a major MVC rule and teaches a real bad habit: Views shouldn't have any
knowledge of Models and Models shouldn't care who's using them
(Controllers are just conduits between Views and Models). On a larger
scale, this would present itself to be a huge maintenance nightmare and
dependencies have now been created. Everything should be independent of
each other enough that I could replace one section without affecting the
operation of anything else in the application. In this case. the
controller should be passing either Value or Transfer Objects back and
forth between the View and Model. This way, I could change models on the
fly and the controller and view wouldn't suspect a thing.

RobotLegs is an excellent example for learning about MVC.



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


Re: [Flashcoders] Fwd: MVC

2012-02-17 Thread Ross Sclafani
I'm firmly against views treating models as anything but read only.

Personal preference I guess

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 17, 2012, at 1:11 PM, Peter Ginneberge p.ginnebe...@telenet.be wrote:

 
 Main problem that I see with the code that was posted is that it breaks
 a major MVC rule and teaches a real bad habit: Views shouldn't have any
 knowledge of Models
 
 Not sure where you get the idea that a View shouldn't communictate with the 
 Model directly:
 
 This states otherwise: 
 http://st-www.cs.illinois.edu/users/smarch/st-docs/mvc.html
 
 quote
 Unlike the model, which may be loosely connected to multiple MVC triads, Each 
 view is associated with a unique controller and vice versa. Instance 
 variables in each maintain this tight coupling. A view's instance variable 
 controller points at its controller, and a controller's instance variable 
 view points at its associated view. And, because both must communicate with 
 their model, each has an instance variable model which points to the model 
 object. So, although the model is limited to sending self changed:, both the 
 view and the controller can send messages directly to each other and to their 
 model.
 /quote
 
 For those wondering why I quote the above article:
 http://en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%93controller#History
 
 regards,
 Muzak
 
 
 - Original Message - From: jchilc...@interactivityunlimited.com
 To: Flash Coders List flashcoders@chattyfig.figleaf.com
 Sent: Thursday, February 16, 2012 3:07 PM
 Subject: RE: [Flashcoders] Fwd: MVC
 
 
 Main problem that I see with the code that was posted is that it breaks
 a major MVC rule and teaches a real bad habit: Views shouldn't have any
 knowledge of Models and Models shouldn't care who's using them
 (Controllers are just conduits between Views and Models). On a larger
 scale, this would present itself to be a huge maintenance nightmare and
 dependencies have now been created. Everything should be independent of
 each other enough that I could replace one section without affecting the
 operation of anything else in the application. In this case. the
 controller should be passing either Value or Transfer Objects back and
 forth between the View and Model. This way, I could change models on the
 fly and the controller and view wouldn't suspect a thing.
 
 RobotLegs is an excellent example for learning about MVC.
 
 
 ___
 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] Fwd: MVC

2012-02-16 Thread Ross Sclafani
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


Re: [Flashcoders] Fwd: MVC

2012-02-16 Thread Beatrix Krümmer-Frau

perfect! Can I use this for my Flash students?

Am 16.02.2012 08:59, schrieb Ross Sclafani:

From: Ross Sclafaniross.sclaf...@gmail.com
Date: February 16, 2012 2:39:34 AM EST
To: Corc...@chello.nl
Cc: Flash Coders Listflashcoders@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


Re: [Flashcoders] Fwd: MVC

2012-02-16 Thread Paul Andrews

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 Sclafaniross.sclaf...@gmail.com
Date: February 16, 2012 2:39:34 AM EST
To: Corc...@chello.nl
Cc: Flash Coders Listflashcoders@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


Re: [Flashcoders] Fwd: MVC

2012-02-16 Thread tom rhodes
traditional vanilla MVC tends to use composition like the example given,
check out robotlegs if you don't like it :) then you inject dependencies
instead of passing them around and everything gets a bit more loosely
coupled...

On 16 February 2012 11:46, 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 Sclafaniross.sclafani@gmail.**com ross.sclaf...@gmail.com
 Date: February 16, 2012 2:39:34 AM EST
 To: Corc...@chello.nl
 Cc: Flash Coders 
 Listflashcoders@chattyfig.**figleaf.comflashcoders@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 Flashcoders@chattyfig.figleaf.com
 http://chattyfig.figleaf.com/**mailman/listinfo/flashcodershttp://chattyfig.figleaf.com/mailman/listinfo/flashcoders


 __**_
 Flashcoders mailing list
 Flashcoders@chattyfig.figleaf.**com Flashcoders@chattyfig.figleaf.com
 http://chattyfig.figleaf.com/**mailman/listinfo/flashcodershttp://chattyfig.figleaf.com/mailman/listinfo/flashcoders

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


Re: [Flashcoders] Fwd: MVC

2012-02-16 Thread Paul Andrews

On 16/02/2012 10:54, tom rhodes wrote:

traditional vanilla MVC tends to use composition like the example given,
check out robotlegs if you don't like it :) then you inject dependencies
instead of passing them around and everything gets a bit more loosely
coupled...


It's not a question of not liking it - your example is perfect for a 
coded-only solution, slightly less practical when working in a 
mixed-mode with the Flash IDE being involved in view instantiation.




On 16 February 2012 11:46, Paul Andrewsp...@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 Sclafaniross.sclafani@gmail.**comross.sclaf...@gmail.com
Date: February 16, 2012 2:39:34 AM EST
To: Corc...@chello.nl
Cc: Flash Coders 
Listflashcoders@chattyfig.**figleaf.comflashcoders@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.**comFlashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/**mailman/listinfo/flashcodershttp://chattyfig.figleaf.com/mailman/listinfo/flashcoders



__**_
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.**comFlashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/**mailman/listinfo/flashcodershttp://chattyfig.figleaf.com/mailman/listinfo/flashcoders



Re: [Flashcoders] Fwd: MVC

2012-02-16 Thread Paul Andrews

On 16/02/2012 11:11, Paul Andrews wrote:

On 16/02/2012 10:54, tom rhodes wrote:

traditional vanilla MVC tends to use composition like the example given,
check out robotlegs if you don't like it :) then you inject dependencies
instead of passing them around and everything gets a bit more loosely
coupled...


It's not a question of not liking it - your example is perfect for a 
coded-only solution, slightly less practical when working in a 
mixed-mode with the Flash IDE being involved in view instantiation.


I should say Tom's example..





On 16 February 2012 11:46, Paul Andrewsp...@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 
Sclafaniross.sclafani@gmail.**comross.sclaf...@gmail.com

Date: February 16, 2012 2:39:34 AM EST
To: Corc...@chello.nl
Cc: Flash Coders 
Listflashcoders@chattyfig.**figleaf.comflashcoders@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


Re: [Flashcoders] Fwd: MVC

2012-02-16 Thread tom rhodes
um, Ross gave it i think dude.

i didn't give any code examples :)

maybe you missed the smiley after i said if you don't like it, perhaps
shoudl have been a ;). what problems do you have using assets mad ein the
IDE with mvc?

On 16 February 2012 12:21, Paul Andrews p...@ipauland.com wrote:

 On 16/02/2012 11:11, Paul Andrews wrote:

 On 16/02/2012 10:54, tom rhodes wrote:

 traditional vanilla MVC tends to use composition like the example given,
 check out robotlegs if you don't like it :) then you inject dependencies
 instead of passing them around and everything gets a bit more loosely
 coupled...


 It's not a question of not liking it - your example is perfect for a
 coded-only solution, slightly less practical when working in a mixed-mode
 with the Flash IDE being involved in view instantiation.


 I should say Tom's example..




 On 16 February 2012 11:46, Paul Andrewsp...@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 Sclafaniross.sclafani@gmail.com
 ross.sclaf...@gmail.com
 Date: February 16, 2012 2:39:34 AM EST
 To: Corc...@chello.nl
 Cc: Flash Coders 
 Listflashcoders@chattyfig.**f**igleaf.comhttp://figleaf.com
 flashcoders@**chattyfig.figleaf.comflashcoders@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


 

Re: [Flashcoders] Fwd: MVC

2012-02-16 Thread Paul Andrews

On 16/02/2012 12:04, tom rhodes wrote:

um, Ross gave it i think dude.

Yes, I posted a correction..


i didn't give any code examples :)

maybe you missed the smiley after i said if you don't like it, perhaps
shoudl have been a ;). what problems do you have using assets mad ein the
IDE with mvc?
Ross' example passed the model and controller via the constructor. If 
you build a view using the IDE and leave things sitting inside a MC or 
the stage, you won't be calling the constructor, the IDE will write code 
to instantiate those components for you, so passing the arguments can be 
a problem.


There's also a school of thought that initialisation is best done in a 
separate function separately to the constructor, so that an instance can 
be re-initialised multiple times. That's more about OO than MVC.


Ross' example is superb. My small point is made for anyone coming new to 
OO programing and trying to marry the two worlds of the timeline/code 
development with MVC.


Ross' example for the view would be like this (allowing the IDE to 
instantiate and the user to hook up the model and controller):


public function View(model:Model=null, 
controller:Controller=null){
super();
if ( model != null){
init(model, controller);
}
}

public function init(model:Model, controller:Controller){
model.addEventListener(Event.CHANGE, 
this.model_changeHandler);
this.model = model;
this.controller = controller;
this.addChild(this.textField);
this.stage.addEventListener(MouseEvent.CLICK, 
this.stage_clickHandler)
}

I definitely agree that Ross' example is the most succinct MVC example I've 
ever seen.

Top job.




On 16 February 2012 12:21, Paul Andrewsp...@ipauland.com  wrote:


On 16/02/2012 11:11, Paul Andrews wrote:


On 16/02/2012 10:54, tom rhodes wrote:


traditional vanilla MVC tends to use composition like the example given,
check out robotlegs if you don't like it :) then you inject dependencies
instead of passing them around and everything gets a bit more loosely
coupled...


It's not a question of not liking it - your example is perfect for a
coded-only solution, slightly less practical when working in a mixed-mode
with the Flash IDE being involved in view instantiation.


I should say Tom's example..




On 16 February 2012 11:46, Paul Andrewsp...@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 Sclafaniross.sclafani@gmail.com

ross.sclaf...@gmail.com
Date: February 16, 2012 2:39:34 AM EST
To: Corc...@chello.nl
Cc: Flash Coders Listflashcoders@chattyfig.**f**igleaf.comhttp://figleaf.com
flashcoders@**chattyfig.figleaf.comflashcoders@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 

Re: [Flashcoders] Fwd: MVC

2012-02-16 Thread Ross Sclafani
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 Sclafaniross.sclaf...@gmail.com
 Date: February 16, 2012 2:39:34 AM EST
 To: Corc...@chello.nl
 Cc: Flash Coders Listflashcoders@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


Re: [Flashcoders] Fwd: MVC

2012-02-16 Thread Ross Sclafani
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 birik...@hotmail.de wrote:

 perfect! Can I use this for my Flash students?
 
 Am 16.02.2012 08:59, schrieb Ross Sclafani:
 From: Ross Sclafaniross.sclaf...@gmail.com
 Date: February 16, 2012 2:39:34 AM EST
 To: Corc...@chello.nl
 Cc: Flash Coders Listflashcoders@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


RE: [Flashcoders] Fwd: MVC

2012-02-16 Thread Cor
Ross,

And you did get people started.
At least me!

I am also very interested in your fuller framework.
I don't wish to use the big frameworks as RobotLegs, etc.
I want to learn to create good MVC from scratch.

Best regards,
Cor van Dooren


-Original Message-
From: flashcoders-boun...@chattyfig.figleaf.com
[mailto:flashcoders-boun...@chattyfig.figleaf.com] On Behalf Of Ross
Sclafani
Sent: donderdag 16 februari 2012 14:28
To: Flash Coders List
Subject: Re: [Flashcoders] Fwd: MVC

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 Sclafaniross.sclaf...@gmail.com
 Date: February 16, 2012 2:39:34 AM EST
 To: Corc...@chello.nl
 Cc: Flash Coders Listflashcoders@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

RE: [Flashcoders] Fwd: MVC

2012-02-16 Thread jchilcott

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


RE: [Flashcoders] Fwd: MVC

2012-02-16 Thread jchilcott
(UGH... I hate RTF Web editors)

RobotLegs is not a big framework at all. In comparison with most of the
other frameworks out there, it's overhead is far far less than ones like
Cairngorm, Spring and Parsley. Even compared to Mate and SWIZ (which are
very small to begin with), then RobotLegs is lighter at 47K overhead.

Main problem that I see with the code that was posted is that it breaks
a major MVC rule and teaches a real bad habit: Views shouldn't have any
knowledge of Models and Models shouldn't care who's using them
(Controllers are just conduits between Views and Models). On a larger
scale, this would present itself to be a huge maintenance nightmare and
dependencies have now been created. Everything should be independent of
each other enough that I could replace one section without affecting the
operation of anything else in the application. In this case. the
controller should be passing either Value or Transfer Objects back and
forth between the View and Model. This way, I could change models on the
fly and the controller and view wouldn't suspect a thing.

RobotLegs is an excellent example for learning about MVC.

jord
 Original Message 
Subject: RE: [Flashcoders] Fwd: MVC
From: Cor c...@chello.nl
Date: Thu, February 16, 2012 8:39 am
To: 'Flash Coders List' flashcoders@chattyfig.figleaf.com

Ross,

And you did get people started.
At least me!

I am also very interested in your fuller framework.
I don't wish to use the big frameworks as RobotLegs, etc.
I want to learn to create good MVC from scratch.

Best regards,
Cor van Dooren


-Original Message-
From: flashcoders-boun...@chattyfig.figleaf.com
[mailto:flashcoders-boun...@chattyfig.figleaf.com] On Behalf Of Ross
Sclafani
Sent: donderdag 16 februari 2012 14:28
To: Flash Coders List
Subject: Re: [Flashcoders] Fwd: MVC

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


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


RE: [Flashcoders] Fwd: MVC

2012-02-16 Thread Cor
Me, being Dutch, is having all the problems expressing in a non-native language.
I did not mean to offend ANY framework.
Sure RobotLegs is perfect, as many people use it.
I am only trying to get some help/examples to write a somewhat fuller MVC 
myself.

So I am sorry!

Best regards,
Cor van Dooren
--
Answers in Dutch are also very much appreciated. ;-)

-Original Message-
From: flashcoders-boun...@chattyfig.figleaf.com 
[mailto:flashcoders-boun...@chattyfig.figleaf.com] On Behalf Of 
jchilc...@interactivityunlimited.com
Sent: donderdag 16 februari 2012 15:07
To: Flash Coders List
Subject: RE: [Flashcoders] Fwd: MVC

(UGH... I hate RTF Web editors)

RobotLegs is not a big framework at all. In comparison with most of the other 
frameworks out there, it's overhead is far far less than ones like Cairngorm, 
Spring and Parsley. Even compared to Mate and SWIZ (which are very small to 
begin with), then RobotLegs is lighter at 47K overhead.

Main problem that I see with the code that was posted is that it breaks a major 
MVC rule and teaches a real bad habit: Views shouldn't have any knowledge of 
Models and Models shouldn't care who's using them (Controllers are just 
conduits between Views and Models). On a larger scale, this would present 
itself to be a huge maintenance nightmare and dependencies have now been 
created. Everything should be independent of each other enough that I could 
replace one section without affecting the operation of anything else in the 
application. In this case. the controller should be passing either Value or 
Transfer Objects back and forth between the View and Model. This way, I could 
change models on the fly and the controller and view wouldn't suspect a thing.

RobotLegs is an excellent example for learning about MVC.

jord
 Original Message 
Subject: RE: [Flashcoders] Fwd: MVC
From: Cor c...@chello.nl
Date: Thu, February 16, 2012 8:39 am
To: 'Flash Coders List' flashcoders@chattyfig.figleaf.com

Ross,

And you did get people started.
At least me!

I am also very interested in your fuller framework.
I don't wish to use the big frameworks as RobotLegs, etc.
I want to learn to create good MVC from scratch.

Best regards,
Cor van Dooren


-Original Message-
From: flashcoders-boun...@chattyfig.figleaf.com
[mailto:flashcoders-boun...@chattyfig.figleaf.com] On Behalf Of Ross Sclafani
Sent: donderdag 16 februari 2012 14:28
To: Flash Coders List
Subject: Re: [Flashcoders] Fwd: MVC

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


___
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