home *** CD-ROM | disk | FTP | other *** search
/ Ice Age Fan CD 1 / CD1_Scrat.iso / flash / data / game.swf / scripts / com / google / analytics / debug / UISprite.as < prev    next >
Encoding:
Text File  |  2012-07-04  |  5.5 KB  |  206 lines

  1. package com.google.analytics.debug
  2. {
  3.    import flash.display.DisplayObject;
  4.    import flash.display.Sprite;
  5.    import flash.display.Stage;
  6.    import flash.events.Event;
  7.    
  8.    public class UISprite extends Sprite
  9.    {
  10.       private var _forcedWidth:uint;
  11.       
  12.       public var margin:Margin;
  13.       
  14.       protected var alignTarget:DisplayObject;
  15.       
  16.       protected var listenResize:Boolean;
  17.       
  18.       public var alignement:Align;
  19.       
  20.       private var _forcedHeight:uint;
  21.       
  22.       public function UISprite(param1:DisplayObject = null)
  23.       {
  24.          super();
  25.          listenResize = false;
  26.          alignement = Align.none;
  27.          this.alignTarget = param1;
  28.          margin = new Margin();
  29.          addEventListener(Event.ADDED_TO_STAGE,_onAddedToStage);
  30.          addEventListener(Event.REMOVED_FROM_STAGE,_onRemovedFromStage);
  31.       }
  32.       
  33.       public function get forcedHeight() : uint
  34.       {
  35.          if(_forcedHeight)
  36.          {
  37.             return _forcedHeight;
  38.          }
  39.          return height;
  40.       }
  41.       
  42.       private function _onAddedToStage(param1:Event) : void
  43.       {
  44.          layout();
  45.          resize();
  46.       }
  47.       
  48.       protected function dispose() : void
  49.       {
  50.          var _loc1_:DisplayObject = null;
  51.          var _loc2_:int = 0;
  52.          while(_loc2_ < numChildren)
  53.          {
  54.             _loc1_ = getChildAt(_loc2_);
  55.             if(_loc1_)
  56.             {
  57.                removeChild(_loc1_);
  58.             }
  59.             _loc2_++;
  60.          }
  61.       }
  62.       
  63.       public function set forcedHeight(param1:uint) : void
  64.       {
  65.          _forcedHeight = param1;
  66.       }
  67.       
  68.       public function set forcedWidth(param1:uint) : void
  69.       {
  70.          _forcedWidth = param1;
  71.       }
  72.       
  73.       protected function layout() : void
  74.       {
  75.       }
  76.       
  77.       public function get forcedWidth() : uint
  78.       {
  79.          if(_forcedWidth)
  80.          {
  81.             return _forcedWidth;
  82.          }
  83.          return width;
  84.       }
  85.       
  86.       public function alignTo(param1:Align, param2:DisplayObject = null) : void
  87.       {
  88.          var _loc3_:uint = 0;
  89.          var _loc4_:uint = 0;
  90.          var _loc5_:uint = 0;
  91.          var _loc6_:uint = 0;
  92.          var _loc7_:UISprite = null;
  93.          if(param2 == null)
  94.          {
  95.             if(parent is Stage)
  96.             {
  97.                param2 = this.stage;
  98.             }
  99.             else
  100.             {
  101.                param2 = parent;
  102.             }
  103.          }
  104.          if(param2 == this.stage)
  105.          {
  106.             if(this.stage == null)
  107.             {
  108.                return;
  109.             }
  110.             _loc3_ = uint(this.stage.stageHeight);
  111.             _loc4_ = uint(this.stage.stageWidth);
  112.             _loc5_ = 0;
  113.             _loc6_ = 0;
  114.          }
  115.          else
  116.          {
  117.             _loc7_ = param2 as UISprite;
  118.             if(_loc7_.forcedHeight)
  119.             {
  120.                _loc3_ = _loc7_.forcedHeight;
  121.             }
  122.             else
  123.             {
  124.                _loc3_ = _loc7_.height;
  125.             }
  126.             if(_loc7_.forcedWidth)
  127.             {
  128.                _loc4_ = _loc7_.forcedWidth;
  129.             }
  130.             else
  131.             {
  132.                _loc4_ = _loc7_.width;
  133.             }
  134.             _loc5_ = 0;
  135.             _loc6_ = 0;
  136.          }
  137.          switch(param1)
  138.          {
  139.             case Align.top:
  140.                x = _loc4_ / 2 - forcedWidth / 2;
  141.                y = _loc6_ + margin.top;
  142.                break;
  143.             case Align.bottom:
  144.                x = _loc4_ / 2 - forcedWidth / 2;
  145.                y = _loc6_ + _loc3_ - forcedHeight - margin.bottom;
  146.                break;
  147.             case Align.left:
  148.                x = _loc5_ + margin.left;
  149.                y = _loc3_ / 2 - forcedHeight / 2;
  150.                break;
  151.             case Align.right:
  152.                x = _loc5_ + _loc4_ - forcedWidth - margin.right;
  153.                y = _loc3_ / 2 - forcedHeight / 2;
  154.                break;
  155.             case Align.center:
  156.                x = _loc4_ / 2 - forcedWidth / 2;
  157.                y = _loc3_ / 2 - forcedHeight / 2;
  158.                break;
  159.             case Align.topLeft:
  160.                x = _loc5_ + margin.left;
  161.                y = _loc6_ + margin.top;
  162.                break;
  163.             case Align.topRight:
  164.                x = _loc5_ + _loc4_ - forcedWidth - margin.right;
  165.                y = _loc6_ + margin.top;
  166.                break;
  167.             case Align.bottomLeft:
  168.                x = _loc5_ + margin.left;
  169.                y = _loc6_ + _loc3_ - forcedHeight - margin.bottom;
  170.                break;
  171.             case Align.bottomRight:
  172.                x = _loc5_ + _loc4_ - forcedWidth - margin.right;
  173.                y = _loc6_ + _loc3_ - forcedHeight - margin.bottom;
  174.          }
  175.          if(!listenResize && param1 != Align.none)
  176.          {
  177.             param2.addEventListener(Event.RESIZE,onResize,false,0,true);
  178.             listenResize = true;
  179.          }
  180.          this.alignement = param1;
  181.          this.alignTarget = param2;
  182.       }
  183.       
  184.       private function _onRemovedFromStage(param1:Event) : void
  185.       {
  186.          removeEventListener(Event.ADDED_TO_STAGE,_onAddedToStage);
  187.          removeEventListener(Event.REMOVED_FROM_STAGE,_onRemovedFromStage);
  188.          dispose();
  189.       }
  190.       
  191.       public function resize() : void
  192.       {
  193.          if(alignement != Align.none)
  194.          {
  195.             alignTo(alignement,alignTarget);
  196.          }
  197.       }
  198.       
  199.       protected function onResize(param1:Event) : void
  200.       {
  201.          resize();
  202.       }
  203.    }
  204. }
  205.  
  206.