Hi I’m learning MVC and wanted to start out with a simple program that counts mouse clicks on the stage. Any help would be great. There’s no library objects on the stage linked to anything. Everything is done in code.
I’m receiving error -
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at Controller()
at run_fla::MainTimeline/frame1()
model
package {
import flash.events.EventDispatcher;
import flash.events.Event;
public class Model extends EventDispatcher {
private var _clicks:Number;
public static const COUNT_CLICK:String = "clicked";
public function Model(){
}
public function set clicks(num:Number):void {
_clicks = _clicks + num;
dispatchEvent(new Event(Model.COUNT_CLICK));
}
}
}
controller
package {
import flash.display.*;
import flash.events.*;
public class Controller extends MovieClip {
private var model:Model;
public function Controller(m){
model = m;
this.parent.stage.addEventListener(MouseEvent.CLICK, go);
}
public function go(event:MouseEvent):void {
model.clicks = 1;
}
}
}
fla I don’t have a doucment class or view class yet.
var m:Model = new Model();
var c:Controller = new Controller(m);
addChild(c);