home *** CD-ROM | disk | FTP | other *** search
- package com.livebrush.utils
- {
- import flash.events.EventDispatcher;
-
- public class Model extends EventDispatcher
- {
- public var views:Array;
-
- public function Model()
- {
- super();
- this.views = [];
- this.init();
- }
-
- private function init() : void
- {
- }
-
- protected function unregisterView(view:View) : View
- {
- var viewIndex:int = int(this.views.indexOf(view));
- if(viewIndex > -1)
- {
- this.views.splice(viewIndex,1);
- }
- return view;
- }
-
- protected function updateViews(update:Update) : void
- {
- for(var i:int = 0; i < this.views.length; i++)
- {
- this.views[i].update(update);
- }
- }
-
- protected function die() : void
- {
- for(var i:int = 0; i < this.views.length; i++)
- {
- if(this.views[i].die != null)
- {
- this.views[i].die();
- }
- }
- this.views = [];
- }
-
- protected function registerView(view:View) : View
- {
- this.views.push(view);
- return view;
- }
-
- public function update(update:Update, views:Boolean = true, dispatch:Boolean = false) : void
- {
- if(views)
- {
- this.updateViews(update);
- }
- if(dispatch)
- {
- dispatchEvent(update.generateEvent());
- }
- }
- }
- }
-
-