Hey All
I’m practicing MVC design pattern and it involves getting and setting which is where i think the problem may be here are the classes
MVCDocument
package
{
import flash.display.Sprite;
public class MVCDocument extends Sprite
{
public var _model:MVCModel;
public var _controller:MVCController;
public var _view:MVCView;
public function MVCDocument():void
{
_model = new MVCModel();
_controller = new MVCController(_model);
_view = new MVCView(_model,_controller);
addChild(_view);
}
}
}
[RIGHT]
[LEFT]MVCView
package
{
import flash.display.ShaderInput;
import flash.display.Sprite;
import flash.events.Event;
import flash.events.KeyboardEvent;
/**
* ...
*
*/
public class MVCView extends Sprite
{
private var ship:Ship = new Ship;
private var _model:Object;
private var _controller:Object;
public function MVCView(MVCModel:Object,MVCController:Object):void
{
_model = MVCModel;
_model.addEventListener(Event.CHANGE, changeHandler);
_controller = MVCController;
addEventListener(Event.ADDED_TO_STAGE, addedToStage);
}
public function addedToStage(evt:Event):void
{
ship.x = 100;
ship.y = 100;
addChild(ship);
stage.addEventListener(KeyboardEvent.KEY_DOWN, onKeyDown);
removeEventListener(Event.ADDED_TO_STAGE,addedToStage)
}
public function onKeyDown(evt:KeyboardEvent):void
{
_controller.processKeyDownEvent(evt);
}
public function changeHandler(evt:Event):void
{
ship.rotation = _model._rotationValue;
}
}
}
MVCController
package
{
import flash.events.KeyboardEvent;
import flash.ui.Keyboard;
/**
* ...
*
*/
public class MVCController
{
private var _model:Object
public function MVCController(MVCModel:Object):void
{
_model = MVCModel;
}
public function processKeyDownEvent(evt:KeyboardEvent):void
{
switch(evt.keyCode)
{
case Keyboard.LEFT:
_model._rotationSpeed -=5;
trace("roationSetFrom Controller")
break;
case Keyboard.RIGHT:
_model._rotationSpeed += 5;
trace("roationSetFrom Controller")
break;
}
}
}
}
MVCModel
package
{
import flash.events.EventDispatcher;
import flash.events.Event;
/**
* ...
*
*/
public class MVCModel extends EventDispatcher
{
public var _rotationValue:Number;
public var _rotationSpeed:Number;
public function MVCModel()
{
_rotationValue=0;
trace("rotationValue = " + _rotationValue);
}
public function update():void
{
trace("_rotationValue = "+ _rotationValue);
//_rotationValue += _rotationSpeed;
_rotationSpeed += _rotationValue;
}
public function get rotationValue():Number
{
return _rotationValue;
}
public function set rotationValue (value:Number)
{
_rotationValue = value;
trace("rotVal Set");
dispatchEvent(new Event(Event.CHANGE));
}
}
}
the last trace i get is the one in the switch statement in the keyboardeventHandler funtion in MVCController
so I’m at a loss:block:
[/LEFT]
[/RIGHT]