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 / graphics / DecoGroup.as < prev    next >
Encoding:
Text File  |  2009-10-26  |  3.2 KB  |  130 lines

  1. package com.livebrush.graphics
  2. {
  3.    import com.livebrush.data.Settings;
  4.    import com.livebrush.styles.DecoAsset;
  5.    import flash.events.Event;
  6.    import flash.events.EventDispatcher;
  7.    
  8.    public class DecoGroup extends EventDispatcher
  9.    {
  10.       private var decos:Array;
  11.       
  12.       private var decoLoadCount:int;
  13.       
  14.       public function DecoGroup()
  15.       {
  16.          super();
  17.          this.decos = [];
  18.          this.decoLoadCount = 0;
  19.       }
  20.       
  21.       public function removeDecoIndex(index:int) : void
  22.       {
  23.          this.decos[index].die();
  24.          delete this.decos[index];
  25.          this.decos.splice(index,1);
  26.       }
  27.       
  28.       public function getDeco(index:int) : Deco
  29.       {
  30.          return this.decos[index];
  31.       }
  32.       
  33.       private function decoCompleteHandler(e:Event) : void
  34.       {
  35.          e.target.removeEventListener(e.type,this.decoCompleteHandler);
  36.          this.decoComplete();
  37.       }
  38.       
  39.       public function get loaded() : Boolean
  40.       {
  41.          var loaded:Boolean = true;
  42.          for(var i:int = 0; i < this.decos.length; i++)
  43.          {
  44.             loaded = Boolean(this.decos[i].loaded);
  45.          }
  46.          return loaded;
  47.       }
  48.       
  49.       public function get latest() : Deco
  50.       {
  51.          return this.decos[this.decos.length - 1];
  52.       }
  53.       
  54.       public function addDecoObj(deco:Deco) : void
  55.       {
  56.          if(!deco.loaded)
  57.          {
  58.             deco.addEventListener(Event.COMPLETE,this.decoCompleteHandler);
  59.          }
  60.          else
  61.          {
  62.             this.decoComplete();
  63.          }
  64.          this.decos.push(deco);
  65.       }
  66.       
  67.       public function get decoList() : Array
  68.       {
  69.          return this.decos.slice();
  70.       }
  71.       
  72.       public function get length() : int
  73.       {
  74.          return this.decos.length;
  75.       }
  76.       
  77.       public function addDeco(decoAsset:DecoAsset, initObj:Settings) : void
  78.       {
  79.          var newDeco:Deco = new Deco(decoAsset,initObj);
  80.          if(!newDeco.loaded)
  81.          {
  82.             newDeco.addEventListener(Event.COMPLETE,this.decoCompleteHandler);
  83.          }
  84.          else
  85.          {
  86.             this.decoComplete();
  87.          }
  88.          this.decos.push(newDeco);
  89.       }
  90.       
  91.       public function removeAllDecos() : void
  92.       {
  93.          while(this.length > 0)
  94.          {
  95.             this.removeDecoIndex(0);
  96.          }
  97.       }
  98.       
  99.       public function removeDeco(id:int) : void
  100.       {
  101.          this.removeDecoIndex(Settings.idToIndex(id.toString(),this.decos,"id"));
  102.       }
  103.       
  104.       private function decoComplete() : void
  105.       {
  106.          ++this.decoLoadCount;
  107.          if(this.decoLoadCount == this.length)
  108.          {
  109.             this.groupComplete();
  110.          }
  111.       }
  112.       
  113.       public function copy() : DecoGroup
  114.       {
  115.          var newDecoGroup:DecoGroup = new DecoGroup();
  116.          for(var i:int = 0; i < this.decos.length; i++)
  117.          {
  118.             newDecoGroup.addDeco(this.decos[i].decoAsset.copy(),this.decos[i].initObj);
  119.          }
  120.          return newDecoGroup;
  121.       }
  122.       
  123.       private function groupComplete() : void
  124.       {
  125.          dispatchEvent(new Event(Event.COMPLETE,true,false));
  126.       }
  127.    }
  128. }
  129.  
  130.