Note that there are some explanatory texts on larger screens.

plurals
  1. PONeed help understand MVC implementation within Actionscript 3 AS3, please
    primarykey
    data
    text
    <p>I am learning MVC implementation with ActionScript 3.0. So far, I have done alright but have couple of questions that can make this learning process very pleasant for me. I would highly appreciate your help and wisdom.</p> <p>Let me explain how I am implementing a simple MVC implementation:</p> <p>My Flash Movie is called FusionMVC. I have all the MVC files within the same package like this:</p> <p>DataModel DataControl DataView Application Facade</p> <p>Here are my question:</p> <p>As I understand it correctly, whenever I need to place a display object on the main stage, I declare or implement that display object in DataView class, am I right?</p> <p>I have a symbol/display object called "Box" in the main library. I add this symbol to the stage by instantiating it within DataView class which I am able to see at runtime. Now if I need to add an EventListener called "ClickHandler" to this object:</p> <p>Where do I declare this "ClickHandler" event, please? I am currently declaring it in the DataModel Class.</p> <p>What I am confused about is to where to declare the EventHandler Methods. DataModel, or DataControl?</p> <p>Thank you for your help. Here is the entire code:</p> <pre><code>//DATAMODEL package { import flash.events.*; import flash.errors.*; public class DataModel extends EventDispatcher { public static const UPDATE:String = "modelUpdaed"; private var _txt:String; public function DataModel() { } public function get Text():String { return _txt; } public function set Text(p:String):void { _txt = p; notifyObserver(); trace("MODEL HAS BEEN CHANGED"); } public function notifyObserver():void { dispatchEvent(new Event(DataModel.UPDATE)); } public function sayHello(e:Event):void { trace("HEY HELLO"); } } } //DATACONTROL package { import flash.display.*; import flash.events.*; import flash.errors.*; public class DataControl { private var _model:DataModel; public function DataControl(m:DataModel) { _model = m; } } } //DATAVIEW package { import flash.display.*; import flash.events.*; import flash.errors.*; public class DataView extends Sprite { private var _model:DataModel; private var _control:DataControl; public var b:Box; public function DataView(m:DataModel, c:DataControl) { _model = m; _control = c; addBox(); } public function addBox():void { b = new Box(); b.x = b.y = 150; //b.addEventListener(MouseEvent.CLICK, vHandler); addChild(b); } } } //APPLICATION FACADE package { import flash.display.*; import flash.events.*; import flash.errors.*; public class Main extends Sprite { private var _model:DataModel; private var _control:DataControl; private var _view:DataView; public function Main() { _model = new DataModel(); _control = new DataControl(_model); _view = new DataView(_model, _control); addChild(_view); } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload