New to MVC. Actionscript 3.0 Appreciate your help.

Posted by Combustion007 on Stack Overflow See other posts from Stack Overflow or by Combustion007
Published on 2010-03-13T20:30:09Z Indexed on 2010/03/13 20:35 UTC
Read the original article Hit count: 208

Filed under:
|
|

Hello Everyone,

I am new to design patterns and am trying to learn the MVC implementation. I have written four classes:

DataModel DataView DataController Main

Main serves as the application facade. The main FLA is called HelloWorld. I have a symbol called "Box" in HelloWorld. I just would like to add an instance of the "Box" on the stage. Eventually I would like to place a button and when the button is clicked, the Box instance color will be changed. I would appreciate any help, please help me figure out what am I doing wrong.

Here are my Classes:

DATAMODEL CLASS:

package { import flash.events.*;

public class DataModel extends EventDispatcher
{

    public static const UPDATE:String = "modelUpdate";
    private var _color:Number = (Math.round(Math.random()* 0xffffff));

    public function DataModel()
    {
        trace("DATA MODEL INIT");
    }

    public function get color():Number
    {
        return _color;
    }

    public function set color(p:Number):void
    {
        _color = p;
        notifyObserver();
    }

    public function notifyObserver():void
    {
        dispatchEvent(new Event(DataModel.UPDATE));
    }
}

}

//DATACONTROLLER CLASS:

package { import flash.events.; import flash.display.; import flash.errors.*;

public class DataController
{
    private var _model:DataModel;

    public function DataController(m:DataModel)
    {
        trace("DATACONTROLLER INIT");
        _model = m;
    }



}

}

DATAVIEW CLASS:

package { import flash.events.; import flash.display.; import flash.errors.*;

public class DataView extends Sprite
{

    private var _model:DataModel;
    private var _controller:DataController;
    private var b:Box;

    public function DataView(m:DataModel, c:DataController)
    {
        _model = m;
        _controller = c;

        b = new Box();
        b.x = b.y = 100;
        addChild(b);
    }
}

}

And Finally THE FACADE:

package { import flash.display.; import flash.events.; import flash.text.; import flash.errors.;

public class Main extends Sprite
{
    private var _model:DataModel;
    private var _controller:DataController;
    private var _view:DataView;

    public function Main(m:DataModel, c:DataController, v:DataView)
    {
        _model = m;
        _controller = c;
        _view = v;

        addChild(v);
    }
}

}

When I test the movie: I get this error:

ArgumentError: Error #1063: Argument count mismatch on Main(). Expected 3, got 0.

Thanks alot.

© Stack Overflow or respective owner

Related posts about as3

Related posts about actionscript-3