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

  1. package com.google.analytics.debug
  2. {
  3.    import com.google.analytics.GATracker;
  4.    import com.google.analytics.core.GIFRequest;
  5.    import flash.display.DisplayObject;
  6.    import flash.events.Event;
  7.    import flash.events.KeyboardEvent;
  8.    import flash.net.URLRequest;
  9.    
  10.    public class Layout implements ILayout
  11.    {
  12.       private var _display:DisplayObject;
  13.       
  14.       private var _infoQueue:Array;
  15.       
  16.       private var _maxCharPerLine:int = 85;
  17.       
  18.       private var _hasInfo:Boolean;
  19.       
  20.       private var _warningQueue:Array;
  21.       
  22.       private var _hasDebug:Boolean;
  23.       
  24.       private var _hasWarning:Boolean;
  25.       
  26.       private var _mainPanel:Panel;
  27.       
  28.       private var _GRAlertQueue:Array;
  29.       
  30.       private var _debug:DebugConfiguration;
  31.       
  32.       public var visualDebug:Debug;
  33.       
  34.       private var _hasGRAlert:Boolean;
  35.       
  36.       public function Layout(param1:DebugConfiguration, param2:DisplayObject)
  37.       {
  38.          super();
  39.          _display = param2;
  40.          _debug = param1;
  41.          _hasWarning = false;
  42.          _hasInfo = false;
  43.          _hasDebug = false;
  44.          _hasGRAlert = false;
  45.          _warningQueue = [];
  46.          _infoQueue = [];
  47.          _GRAlertQueue = [];
  48.       }
  49.       
  50.       private function onKey(param1:KeyboardEvent = null) : void
  51.       {
  52.          switch(param1.keyCode)
  53.          {
  54.             case _debug.showHideKey:
  55.                _mainPanel.visible = !_mainPanel.visible;
  56.                break;
  57.             case _debug.destroyKey:
  58.                destroy();
  59.          }
  60.       }
  61.       
  62.       public function createWarning(param1:String) : void
  63.       {
  64.          if(_hasWarning || !isAvailable())
  65.          {
  66.             _warningQueue.push(param1);
  67.             return;
  68.          }
  69.          param1 = _filterMaxChars(param1);
  70.          _hasWarning = true;
  71.          var _loc2_:Warning = new Warning(param1,_debug.warningTimeout);
  72.          addToPanel("analytics",_loc2_);
  73.          _loc2_.addEventListener(Event.REMOVED_FROM_STAGE,_clearWarning,false,0,true);
  74.          if(_hasDebug)
  75.          {
  76.             visualDebug.writeBold(param1);
  77.          }
  78.       }
  79.       
  80.       public function bringToFront(param1:DisplayObject) : void
  81.       {
  82.          _display.stage.setChildIndex(param1,_display.stage.numChildren - 1);
  83.       }
  84.       
  85.       public function createFailureAlert(param1:String) : void
  86.       {
  87.          var _loc2_:AlertAction = null;
  88.          if(_debug.verbose)
  89.          {
  90.             param1 = _filterMaxChars(param1);
  91.             _loc2_ = new AlertAction("Close","close","close");
  92.          }
  93.          else
  94.          {
  95.             _loc2_ = new AlertAction("X","close","close");
  96.          }
  97.          var _loc3_:Alert = new FailureAlert(_debug,param1,[_loc2_]);
  98.          addToPanel("analytics",_loc3_);
  99.          if(_hasDebug)
  100.          {
  101.             if(_debug.verbose)
  102.             {
  103.                param1 = param1.split("\n").join("");
  104.                param1 = _filterMaxChars(param1,66);
  105.             }
  106.             visualDebug.writeBold(param1);
  107.          }
  108.       }
  109.       
  110.       public function init() : void
  111.       {
  112.          var _loc1_:int = 10;
  113.          var _loc2_:uint = uint(_display.stage.stageWidth - _loc1_ * 2);
  114.          var _loc3_:uint = uint(_display.stage.stageHeight - _loc1_ * 2);
  115.          var _loc4_:Panel = new Panel("analytics",_loc2_,_loc3_);
  116.          _loc4_.alignement = Align.top;
  117.          _loc4_.stickToEdge = false;
  118.          _loc4_.title = "Google Analytics v" + GATracker.version;
  119.          _mainPanel = _loc4_;
  120.          addToStage(_loc4_);
  121.          bringToFront(_loc4_);
  122.          if(_debug.minimizedOnStart)
  123.          {
  124.             _mainPanel.onToggle();
  125.          }
  126.          createVisualDebug();
  127.          _display.stage.addEventListener(KeyboardEvent.KEY_DOWN,onKey,false,0,true);
  128.       }
  129.       
  130.       public function addToPanel(param1:String, param2:DisplayObject) : void
  131.       {
  132.          var _loc4_:Panel = null;
  133.          var _loc3_:DisplayObject = _display.stage.getChildByName(param1);
  134.          if(_loc3_)
  135.          {
  136.             _loc4_ = _loc3_ as Panel;
  137.             _loc4_.addData(param2);
  138.          }
  139.          else
  140.          {
  141.             trace("panel \"" + param1 + "\" not found");
  142.          }
  143.       }
  144.       
  145.       private function _clearInfo(param1:Event) : void
  146.       {
  147.          _hasInfo = false;
  148.          if(_infoQueue.length > 0)
  149.          {
  150.             createInfo(_infoQueue.shift());
  151.          }
  152.       }
  153.       
  154.       private function _filterMaxChars(param1:String, param2:int = 0) : String
  155.       {
  156.          var _loc6_:String = null;
  157.          var _loc3_:String = "\n";
  158.          var _loc4_:Array = [];
  159.          var _loc5_:Array = param1.split(_loc3_);
  160.          if(param2 == 0)
  161.          {
  162.             param2 = _maxCharPerLine;
  163.          }
  164.          var _loc7_:int = 0;
  165.          while(_loc7_ < _loc5_.length)
  166.          {
  167.             _loc6_ = _loc5_[_loc7_];
  168.             while(_loc6_.length > param2)
  169.             {
  170.                _loc4_.push(_loc6_.substr(0,param2));
  171.                _loc6_ = _loc6_.substring(param2);
  172.             }
  173.             _loc4_.push(_loc6_);
  174.             _loc7_++;
  175.          }
  176.          return _loc4_.join(_loc3_);
  177.       }
  178.       
  179.       private function _clearGRAlert(param1:Event) : void
  180.       {
  181.          _hasGRAlert = false;
  182.          if(_GRAlertQueue.length > 0)
  183.          {
  184.             createGIFRequestAlert.apply(this,_GRAlertQueue.shift());
  185.          }
  186.       }
  187.       
  188.       public function createSuccessAlert(param1:String) : void
  189.       {
  190.          var _loc2_:AlertAction = null;
  191.          if(_debug.verbose)
  192.          {
  193.             param1 = _filterMaxChars(param1);
  194.             _loc2_ = new AlertAction("Close","close","close");
  195.          }
  196.          else
  197.          {
  198.             _loc2_ = new AlertAction("X","close","close");
  199.          }
  200.          var _loc3_:Alert = new SuccessAlert(_debug,param1,[_loc2_]);
  201.          addToPanel("analytics",_loc3_);
  202.          if(_hasDebug)
  203.          {
  204.             if(_debug.verbose)
  205.             {
  206.                param1 = param1.split("\n").join("");
  207.                param1 = _filterMaxChars(param1,66);
  208.             }
  209.             visualDebug.writeBold(param1);
  210.          }
  211.       }
  212.       
  213.       public function isAvailable() : Boolean
  214.       {
  215.          return _display.stage != null;
  216.       }
  217.       
  218.       public function createAlert(param1:String) : void
  219.       {
  220.          param1 = _filterMaxChars(param1);
  221.          var _loc2_:Alert = new Alert(param1,[new AlertAction("Close","close","close")]);
  222.          addToPanel("analytics",_loc2_);
  223.          if(_hasDebug)
  224.          {
  225.             visualDebug.writeBold(param1);
  226.          }
  227.       }
  228.       
  229.       public function createInfo(param1:String) : void
  230.       {
  231.          if(_hasInfo || !isAvailable())
  232.          {
  233.             _infoQueue.push(param1);
  234.             return;
  235.          }
  236.          param1 = _filterMaxChars(param1);
  237.          _hasInfo = true;
  238.          var _loc2_:Info = new Info(param1,_debug.infoTimeout);
  239.          addToPanel("analytics",_loc2_);
  240.          _loc2_.addEventListener(Event.REMOVED_FROM_STAGE,_clearInfo,false,0,true);
  241.          if(_hasDebug)
  242.          {
  243.             visualDebug.write(param1);
  244.          }
  245.       }
  246.       
  247.       public function createGIFRequestAlert(param1:String, param2:URLRequest, param3:GIFRequest) : void
  248.       {
  249.          var gra:GIFRequestAlert;
  250.          var f:Function;
  251.          var message:String = param1;
  252.          var request:URLRequest = param2;
  253.          var ref:GIFRequest = param3;
  254.          if(_hasGRAlert)
  255.          {
  256.             _GRAlertQueue.push([message,request,ref]);
  257.             return;
  258.          }
  259.          _hasGRAlert = true;
  260.          f = function():void
  261.          {
  262.             ref.sendRequest(request);
  263.          };
  264.          message = _filterMaxChars(message);
  265.          gra = new GIFRequestAlert(message,[new AlertAction("OK","ok",f),new AlertAction("Cancel","cancel","close")]);
  266.          addToPanel("analytics",gra);
  267.          gra.addEventListener(Event.REMOVED_FROM_STAGE,_clearGRAlert,false,0,true);
  268.          if(_hasDebug)
  269.          {
  270.             if(_debug.verbose)
  271.             {
  272.                message = message.split("\n").join("");
  273.                message = _filterMaxChars(message,66);
  274.             }
  275.             visualDebug.write(message);
  276.          }
  277.       }
  278.       
  279.       public function createVisualDebug() : void
  280.       {
  281.          if(!visualDebug)
  282.          {
  283.             visualDebug = new Debug();
  284.             visualDebug.alignement = Align.bottom;
  285.             visualDebug.stickToEdge = true;
  286.             addToPanel("analytics",visualDebug);
  287.             _hasDebug = true;
  288.          }
  289.       }
  290.       
  291.       public function addToStage(param1:DisplayObject) : void
  292.       {
  293.          _display.stage.addChild(param1);
  294.       }
  295.       
  296.       private function _clearWarning(param1:Event) : void
  297.       {
  298.          _hasWarning = false;
  299.          if(_warningQueue.length > 0)
  300.          {
  301.             createWarning(_warningQueue.shift());
  302.          }
  303.       }
  304.       
  305.       public function createPanel(param1:String, param2:uint, param3:uint) : void
  306.       {
  307.          var _loc4_:Panel = new Panel(param1,param2,param3);
  308.          _loc4_.alignement = Align.center;
  309.          _loc4_.stickToEdge = false;
  310.          addToStage(_loc4_);
  311.          bringToFront(_loc4_);
  312.       }
  313.       
  314.       public function destroy() : void
  315.       {
  316.          _mainPanel.close();
  317.          _debug.layout = null;
  318.       }
  319.    }
  320. }
  321.  
  322.