# Where to add event listener in experimental mvc program

**URL:** <https://forum.kirupa.com/t/where-to-add-event-listener-in-experimental-mvc-program/297283>\
**Category:** Uncategorized\
**Created:** [September 29, 2009, 3:19pm UTC](https://forum.kirupa.com/t/where-to-add-event-listener-in-experimental-mvc-program/297283 "2009-09-29T15:19:40Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![mavwrx](https://avatars.discourse-cdn.com/v4/letter/m/cc9497/32.png) [@mavwrx](https://forum.kirupa.com/u/mavwrx)\
**Post date:** [September 29, 2009, 3:19pm UTC](https://forum.kirupa.com/t/where-to-add-event-listener-in-experimental-mvc-program/297283/1 "2009-09-29T15:19:40Z")

</div>

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 -

```auto
TypeError: Error #1009: Cannot access a property or method of a null object reference.
    at Controller()
    at run_fla::MainTimeline/frame1()

```

model

```auto
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

```auto
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.

```auto
var m:Model = new Model(); 
var c:Controller = new Controller(m);
addChild(c);

```
