home *** CD-ROM | disk | FTP | other *** search
/ Mobiclic 161 / MOBICLIC161.ISO / pc / DATA / DSS161 / DSS161_00 / DSS161_00.swf / scripts / dss161 / engineaddons / gamesprotos / Actor.as next >
Text File  |  2014-01-15  |  9KB  |  345 lines

  1. package dss161.engineaddons.gamesprotos
  2. {
  3.    import com.milanpresse.engine.config.Config;
  4.    import dss161.engineaddons.facades.GameEngine;
  5.    import flash.display.MovieClip;
  6.    import flash.display.Stage;
  7.    import flash.system.ApplicationDomain;
  8.    
  9.    public dynamic class Actor implements IElementBase
  10.    {
  11.       
  12.       public static var game:GameEngine;
  13.        
  14.       
  15.       protected var _e:GameEngine;
  16.       
  17.       public var config:Config;
  18.       
  19.       public var stage:Stage;
  20.       
  21.       protected var actors:Vector.<Actor>;
  22.       
  23.       protected var _name:String;
  24.       
  25.       protected var _parentActor:Actor = null;
  26.       
  27.       protected var isSleeping:Boolean = false;
  28.       
  29.       public var vars:Object;
  30.       
  31.       protected var sleepExtern:Function = null;
  32.       
  33.       protected var wakeExtern:Function = null;
  34.       
  35.       protected var destroyExtern:Function = null;
  36.       
  37.       public function Actor(param1:GameEngine = null, param2:Actor = null, param3:* = null)
  38.       {
  39.          this.actors = new Vector.<Actor>();
  40.          this.vars = {};
  41.          super();
  42.          if(param1 != null)
  43.          {
  44.             Actor.game = param1;
  45.          }
  46.          this._e = Actor.game;
  47.          this.stage = Actor.game.stage;
  48.          this._parentActor = param2;
  49.       }
  50.       
  51.       public function start() : void
  52.       {
  53.       }
  54.       
  55.       public function addActor(param1:* = undefined) : *
  56.       {
  57.          var mc:MovieClip = null;
  58.          var actor:Actor = null;
  59.          var classe:Class = null;
  60.          var prop:String = null;
  61.          var params:* = param1;
  62.          if(params is Actor)
  63.          {
  64.             this.actors.push(params);
  65.             params.parentActor = this;
  66.             return params;
  67.          }
  68.          if(params == undefined)
  69.          {
  70.             params = {"type":Actor};
  71.             actor = new Actor(game);
  72.          }
  73.          else
  74.          {
  75.             if(params.type == undefined || params.type == null)
  76.             {
  77.                classe = ApplicationDomain.currentDomain.getDefinition("dss161.engineaddons.gamesprotos.actors.actorClip.ActorClip") as Class;
  78.             }
  79.             else if(params.type is Class)
  80.             {
  81.                classe = params.type;
  82.             }
  83.             else if(params.type is String)
  84.             {
  85.                classe = ApplicationDomain.currentDomain.getDefinition(params.type) as Class;
  86.             }
  87.             delete params.type;
  88.             try
  89.             {
  90.                actor = classe["create"](this._e,params);
  91.             }
  92.             catch(err:Error)
  93.             {
  94.                actor = new classe(params);
  95.             }
  96.          }
  97.          if(actor == null)
  98.          {
  99.             for(prop in params)
  100.             {
  101.             }
  102.             return null;
  103.          }
  104.          actor.parentActor = this;
  105.          if(params.name != undefined)
  106.          {
  107.             actor.name = params.name;
  108.          }
  109.          this.actors.push(actor);
  110.          return actor;
  111.       }
  112.       
  113.       public function getActors() : Array
  114.       {
  115.          var _loc1_:Array = [];
  116.          var _loc2_:int = 0;
  117.          while(_loc2_ < this.actors.length)
  118.          {
  119.             _loc1_.push(this.actors[_loc2_]);
  120.             _loc2_++;
  121.          }
  122.          return _loc1_;
  123.       }
  124.       
  125.       public function getActor(param1:*) : *
  126.       {
  127.          var _loc2_:int = 0;
  128.          var _loc3_:int = 0;
  129.          if(param1 is Actor)
  130.          {
  131.             _loc2_ = this.actors.indexOf(param1);
  132.             if(_loc2_ != -1)
  133.             {
  134.                return this.actors[_loc2_];
  135.             }
  136.          }
  137.          else if(param1 is String)
  138.          {
  139.             _loc3_ = 0;
  140.             while(_loc3_ < this.actors.length)
  141.             {
  142.                if(this.actors[_loc3_].name == param1)
  143.                {
  144.                   return this.actors[_loc3_];
  145.                }
  146.                _loc3_++;
  147.             }
  148.          }
  149.          return null;
  150.       }
  151.       
  152.       public function removeActor(param1:Actor) : void
  153.       {
  154.          if(this.actors.indexOf(param1) != -1)
  155.          {
  156.             this.actors.splice(this.actors.indexOf(param1),1);
  157.          }
  158.       }
  159.       
  160.       public function get sleep() : Function
  161.       {
  162.          return this._sleep;
  163.       }
  164.       
  165.       public function set sleep(param1:Function) : void
  166.       {
  167.          this.sleepExtern = param1;
  168.       }
  169.       
  170.       protected function _sleep() : void
  171.       {
  172.          if(this.sleepExtern != null)
  173.          {
  174.             this.sleepExtern();
  175.          }
  176.          var _loc1_:int = 0;
  177.          while(_loc1_ < this.actors.length)
  178.          {
  179.             if(this.actors[_loc1_] != null)
  180.             {
  181.                this.actors[_loc1_].sleep();
  182.             }
  183.             _loc1_++;
  184.          }
  185.       }
  186.       
  187.       public function get wake() : Function
  188.       {
  189.          return this._wake;
  190.       }
  191.       
  192.       public function set wake(param1:Function) : void
  193.       {
  194.          this.wakeExtern = param1;
  195.       }
  196.       
  197.       protected function _wake() : void
  198.       {
  199.          if(this.wakeExtern != null)
  200.          {
  201.             this.wakeExtern();
  202.          }
  203.          var _loc1_:int = 0;
  204.          while(_loc1_ < this.actors.length)
  205.          {
  206.             if(this.actors[_loc1_] != null)
  207.             {
  208.                this.actors[_loc1_].wake();
  209.             }
  210.             _loc1_++;
  211.          }
  212.       }
  213.       
  214.       public function foreach(param1:Function) : void
  215.       {
  216.          var _loc2_:Vector.<Actor> = this.actors.slice();
  217.          var _loc3_:int = _loc2_.length;
  218.          var _loc4_:int = 0;
  219.          while(_loc4_ < _loc3_)
  220.          {
  221.             if(_loc2_[_loc4_] != null)
  222.             {
  223.                param1(_loc2_[_loc4_]);
  224.             }
  225.             _loc4_++;
  226.          }
  227.       }
  228.       
  229.       public function get destroy() : Function
  230.       {
  231.          return this._destroy;
  232.       }
  233.       
  234.       public function set destroy(param1:Function) : void
  235.       {
  236.          this.destroyExtern = param1;
  237.       }
  238.       
  239.       public function getByProperty(param1:String, param2:*) : *
  240.       {
  241.          var _loc3_:int = this.actors.length;
  242.          var _loc4_:int = 0;
  243.          while(_loc4_ < _loc3_)
  244.          {
  245.             if(this.actors[_loc4_].hasOwnProperty(param1) && this.actors[_loc4_][param1] == param2)
  246.             {
  247.                return this.actors[_loc4_];
  248.             }
  249.             _loc4_++;
  250.          }
  251.          return null;
  252.       }
  253.       
  254.       public function destroyChildren() : void
  255.       {
  256.          var _loc1_:Vector.<Actor> = this.actors.slice();
  257.          var _loc2_:int = _loc1_.length;
  258.          var _loc3_:int = 0;
  259.          while(_loc3_ < _loc2_)
  260.          {
  261.             if(_loc1_[_loc3_] != null)
  262.             {
  263.                _loc1_[_loc3_].destroy();
  264.             }
  265.             _loc3_++;
  266.          }
  267.          this.actors.length = 0;
  268.       }
  269.       
  270.       protected function _destroy() : void
  271.       {
  272.          if(this.destroyExtern != null)
  273.          {
  274.             this.destroyExtern();
  275.          }
  276.          var _loc1_:Vector.<Actor> = this.actors.slice();
  277.          var _loc2_:int = _loc1_.length;
  278.          var _loc3_:int = 0;
  279.          while(_loc3_ < _loc2_)
  280.          {
  281.             if(_loc1_[_loc3_] != null)
  282.             {
  283.                _loc1_[_loc3_].destroy();
  284.             }
  285.             _loc3_++;
  286.          }
  287.          this.actors.length = 0;
  288.          if(this._parentActor != null)
  289.          {
  290.             this._parentActor.removeActor(this);
  291.          }
  292.       }
  293.       
  294.       public function restore() : void
  295.       {
  296.          var _loc1_:Vector.<Actor> = this.actors.slice();
  297.          var _loc2_:int = _loc1_.length;
  298.          var _loc3_:int = 0;
  299.          while(_loc3_ < _loc2_)
  300.          {
  301.             if(_loc1_[_loc3_] != null)
  302.             {
  303.                _loc1_[_loc3_].restore();
  304.             }
  305.             _loc3_++;
  306.          }
  307.       }
  308.       
  309.       public function dissociate() : void
  310.       {
  311.          var _loc1_:Vector.<Actor> = this.actors.slice();
  312.          var _loc2_:int = _loc1_.length;
  313.          var _loc3_:int = 0;
  314.          while(_loc3_ < _loc2_)
  315.          {
  316.             if(_loc1_[_loc3_] != null)
  317.             {
  318.                _loc1_[_loc3_].dissociate();
  319.             }
  320.             _loc3_++;
  321.          }
  322.       }
  323.       
  324.       public function get name() : String
  325.       {
  326.          return this._name;
  327.       }
  328.       
  329.       public function set name(param1:String) : void
  330.       {
  331.          this._name = param1;
  332.       }
  333.       
  334.       public function get parentActor() : Actor
  335.       {
  336.          return this._parentActor;
  337.       }
  338.       
  339.       public function set parentActor(param1:Actor) : void
  340.       {
  341.          this._parentActor = param1;
  342.       }
  343.    }
  344. }
  345.