home *** CD-ROM | disk | FTP | other *** search
/ PCGUIA 2010 Software/Programs / PCGuia_programas.iso / Software / Utils / Livebrush / Install-LivebrushLite.air / livebrush.swf / scripts / com / livebrush / utils / Model.as < prev    next >
Encoding:
Text File  |  2009-10-26  |  1.5 KB  |  70 lines

  1. package com.livebrush.utils
  2. {
  3.    import flash.events.EventDispatcher;
  4.    
  5.    public class Model extends EventDispatcher
  6.    {
  7.       public var views:Array;
  8.       
  9.       public function Model()
  10.       {
  11.          super();
  12.          this.views = [];
  13.          this.init();
  14.       }
  15.       
  16.       private function init() : void
  17.       {
  18.       }
  19.       
  20.       protected function unregisterView(view:View) : View
  21.       {
  22.          var viewIndex:int = int(this.views.indexOf(view));
  23.          if(viewIndex > -1)
  24.          {
  25.             this.views.splice(viewIndex,1);
  26.          }
  27.          return view;
  28.       }
  29.       
  30.       protected function updateViews(update:Update) : void
  31.       {
  32.          for(var i:int = 0; i < this.views.length; i++)
  33.          {
  34.             this.views[i].update(update);
  35.          }
  36.       }
  37.       
  38.       protected function die() : void
  39.       {
  40.          for(var i:int = 0; i < this.views.length; i++)
  41.          {
  42.             if(this.views[i].die != null)
  43.             {
  44.                this.views[i].die();
  45.             }
  46.          }
  47.          this.views = [];
  48.       }
  49.       
  50.       protected function registerView(view:View) : View
  51.       {
  52.          this.views.push(view);
  53.          return view;
  54.       }
  55.       
  56.       public function update(update:Update, views:Boolean = true, dispatch:Boolean = false) : void
  57.       {
  58.          if(views)
  59.          {
  60.             this.updateViews(update);
  61.          }
  62.          if(dispatch)
  63.          {
  64.             dispatchEvent(update.generateEvent());
  65.          }
  66.       }
  67.    }
  68. }
  69.  
  70.