home *** CD-ROM | disk | FTP | other *** search
- package com.livebrush.graphics
- {
- import com.livebrush.data.Settings;
- import com.livebrush.styles.DecoAsset;
- import flash.events.Event;
- import flash.events.EventDispatcher;
-
- public class DecoGroup extends EventDispatcher
- {
- private var decos:Array;
-
- private var decoLoadCount:int;
-
- public function DecoGroup()
- {
- super();
- this.decos = [];
- this.decoLoadCount = 0;
- }
-
- public function removeDecoIndex(index:int) : void
- {
- this.decos[index].die();
- delete this.decos[index];
- this.decos.splice(index,1);
- }
-
- public function getDeco(index:int) : Deco
- {
- return this.decos[index];
- }
-
- private function decoCompleteHandler(e:Event) : void
- {
- e.target.removeEventListener(e.type,this.decoCompleteHandler);
- this.decoComplete();
- }
-
- public function get loaded() : Boolean
- {
- var loaded:Boolean = true;
- for(var i:int = 0; i < this.decos.length; i++)
- {
- loaded = Boolean(this.decos[i].loaded);
- }
- return loaded;
- }
-
- public function get latest() : Deco
- {
- return this.decos[this.decos.length - 1];
- }
-
- public function addDecoObj(deco:Deco) : void
- {
- if(!deco.loaded)
- {
- deco.addEventListener(Event.COMPLETE,this.decoCompleteHandler);
- }
- else
- {
- this.decoComplete();
- }
- this.decos.push(deco);
- }
-
- public function get decoList() : Array
- {
- return this.decos.slice();
- }
-
- public function get length() : int
- {
- return this.decos.length;
- }
-
- public function addDeco(decoAsset:DecoAsset, initObj:Settings) : void
- {
- var newDeco:Deco = new Deco(decoAsset,initObj);
- if(!newDeco.loaded)
- {
- newDeco.addEventListener(Event.COMPLETE,this.decoCompleteHandler);
- }
- else
- {
- this.decoComplete();
- }
- this.decos.push(newDeco);
- }
-
- public function removeAllDecos() : void
- {
- while(this.length > 0)
- {
- this.removeDecoIndex(0);
- }
- }
-
- public function removeDeco(id:int) : void
- {
- this.removeDecoIndex(Settings.idToIndex(id.toString(),this.decos,"id"));
- }
-
- private function decoComplete() : void
- {
- ++this.decoLoadCount;
- if(this.decoLoadCount == this.length)
- {
- this.groupComplete();
- }
- }
-
- public function copy() : DecoGroup
- {
- var newDecoGroup:DecoGroup = new DecoGroup();
- for(var i:int = 0; i < this.decos.length; i++)
- {
- newDecoGroup.addDeco(this.decos[i].decoAsset.copy(),this.decos[i].initObj);
- }
- return newDecoGroup;
- }
-
- private function groupComplete() : void
- {
- dispatchEvent(new Event(Event.COMPLETE,true,false));
- }
- }
- }
-
-