home *** CD-ROM | disk | FTP | other *** search
/ Computer Active 2010 August / CA08.iso / Darbas / kidoz_v1.air / kidoz.swf / scripts / mx / core / Application.as next >
Encoding:
Text File  |  2009-05-06  |  21.6 KB  |  687 lines

  1. package mx.core
  2. {
  3.    import flash.display.DisplayObject;
  4.    import flash.display.InteractiveObject;
  5.    import flash.events.ContextMenuEvent;
  6.    import flash.events.Event;
  7.    import flash.external.ExternalInterface;
  8.    import flash.net.URLRequest;
  9.    import flash.net.navigateToURL;
  10.    import flash.system.Capabilities;
  11.    import flash.ui.ContextMenu;
  12.    import flash.ui.ContextMenuItem;
  13.    import flash.utils.setInterval;
  14.    import mx.containers.utilityClasses.ApplicationLayout;
  15.    import mx.effects.EffectManager;
  16.    import mx.events.FlexEvent;
  17.    import mx.managers.FocusManager;
  18.    import mx.managers.ILayoutManager;
  19.    import mx.managers.ISystemManager;
  20.    import mx.styles.CSSStyleDeclaration;
  21.    import mx.styles.IStyleClient;
  22.    import mx.styles.StyleManager;
  23.    
  24.    use namespace mx_internal;
  25.    
  26.    public class Application extends LayoutContainer
  27.    {
  28.       mx_internal static const VERSION:String = "3.2.0.3958";
  29.       
  30.       mx_internal static var useProgressiveLayout:Boolean = false;
  31.       
  32.       public var preloader:Object;
  33.       
  34.       public var pageTitle:String;
  35.       
  36.       private var resizeWidth:Boolean = true;
  37.       
  38.       private var _applicationViewMetrics:EdgeMetrics;
  39.       
  40.       mx_internal var _parameters:Object;
  41.       
  42.       private var processingCreationQueue:Boolean = false;
  43.       
  44.       public var scriptRecursionLimit:int;
  45.       
  46.       private var resizeHandlerAdded:Boolean = false;
  47.       
  48.       private var preloadObj:Object;
  49.       
  50.       public var usePreloader:Boolean;
  51.       
  52.       mx_internal var _url:String;
  53.       
  54.       private var _viewSourceURL:String;
  55.       
  56.       public var resetHistory:Boolean = true;
  57.       
  58.       public var historyManagementEnabled:Boolean = true;
  59.       
  60.       public var scriptTimeLimit:Number;
  61.       
  62.       public var frameRate:Number;
  63.       
  64.       private var creationQueue:Array = [];
  65.       
  66.       private var resizeHeight:Boolean = true;
  67.       
  68.       public var controlBar:IUIComponent;
  69.       
  70.       private var viewSourceCMI:ContextMenuItem;
  71.       
  72.       public function Application()
  73.       {
  74.          name = "application";
  75.          UIComponentGlobals.mx_internal::layoutManager = ILayoutManager(Singleton.getInstance("mx.managers::ILayoutManager"));
  76.          UIComponentGlobals.mx_internal::layoutManager.usePhasedInstantiation = true;
  77.          if(!ApplicationGlobals.application)
  78.          {
  79.             ApplicationGlobals.application = this;
  80.          }
  81.          super();
  82.          layoutObject = new ApplicationLayout();
  83.          layoutObject.target = this;
  84.          boxLayoutClass = ApplicationLayout;
  85.          showInAutomationHierarchy = true;
  86.       }
  87.       
  88.       public static function get application() : Object
  89.       {
  90.          return ApplicationGlobals.application;
  91.       }
  92.       
  93.       public function set viewSourceURL(param1:String) : void
  94.       {
  95.          _viewSourceURL = param1;
  96.       }
  97.       
  98.       override public function set percentWidth(param1:Number) : void
  99.       {
  100.          super.percentWidth = param1;
  101.          invalidateDisplayList();
  102.       }
  103.       
  104.       override public function prepareToPrint(param1:IFlexDisplayObject) : Object
  105.       {
  106.          var _loc2_:Object = {};
  107.          if(param1 == this)
  108.          {
  109.             _loc2_.width = width;
  110.             _loc2_.height = height;
  111.             _loc2_.verticalScrollPosition = verticalScrollPosition;
  112.             _loc2_.horizontalScrollPosition = horizontalScrollPosition;
  113.             _loc2_.horizontalScrollBarVisible = horizontalScrollBar != null;
  114.             _loc2_.verticalScrollBarVisible = verticalScrollBar != null;
  115.             _loc2_.whiteBoxVisible = whiteBox != null;
  116.             setActualSize(measuredWidth,measuredHeight);
  117.             horizontalScrollPosition = 0;
  118.             verticalScrollPosition = 0;
  119.             if(horizontalScrollBar)
  120.             {
  121.                horizontalScrollBar.visible = false;
  122.             }
  123.             if(verticalScrollBar)
  124.             {
  125.                verticalScrollBar.visible = false;
  126.             }
  127.             if(whiteBox)
  128.             {
  129.                whiteBox.visible = false;
  130.             }
  131.             updateDisplayList(unscaledWidth,unscaledHeight);
  132.          }
  133.          _loc2_.scrollRect = super.prepareToPrint(param1);
  134.          return _loc2_;
  135.       }
  136.       
  137.       override protected function measure() : void
  138.       {
  139.          var _loc2_:Number = NaN;
  140.          super.measure();
  141.          var _loc1_:EdgeMetrics = borderMetrics;
  142.          if(Boolean(controlBar) && Boolean(controlBar.includeInLayout))
  143.          {
  144.             _loc2_ = controlBar.getExplicitOrMeasuredWidth() + _loc1_.left + _loc1_.right;
  145.             measuredWidth = Math.max(measuredWidth,_loc2_);
  146.             measuredMinWidth = Math.max(measuredMinWidth,_loc2_);
  147.          }
  148.       }
  149.       
  150.       override public function getChildIndex(param1:DisplayObject) : int
  151.       {
  152.          if(Boolean(controlBar) && param1 == controlBar)
  153.          {
  154.             return -1;
  155.          }
  156.          return super.getChildIndex(param1);
  157.       }
  158.       
  159.       private function resizeHandler(param1:Event) : void
  160.       {
  161.          var _loc2_:Number = NaN;
  162.          var _loc3_:Number = NaN;
  163.          if(resizeWidth)
  164.          {
  165.             if(isNaN(percentWidth))
  166.             {
  167.                _loc2_ = DisplayObject(systemManager).width;
  168.             }
  169.             else
  170.             {
  171.                super.percentWidth = Math.max(percentWidth,0);
  172.                super.percentWidth = Math.min(percentWidth,100);
  173.                _loc2_ = percentWidth * screen.width / 100;
  174.             }
  175.             if(!isNaN(explicitMaxWidth))
  176.             {
  177.                _loc2_ = Math.min(_loc2_,explicitMaxWidth);
  178.             }
  179.             if(!isNaN(explicitMinWidth))
  180.             {
  181.                _loc2_ = Math.max(_loc2_,explicitMinWidth);
  182.             }
  183.          }
  184.          else
  185.          {
  186.             _loc2_ = width;
  187.          }
  188.          if(resizeHeight)
  189.          {
  190.             if(isNaN(percentHeight))
  191.             {
  192.                _loc3_ = DisplayObject(systemManager).height;
  193.             }
  194.             else
  195.             {
  196.                super.percentHeight = Math.max(percentHeight,0);
  197.                super.percentHeight = Math.min(percentHeight,100);
  198.                _loc3_ = percentHeight * screen.height / 100;
  199.             }
  200.             if(!isNaN(explicitMaxHeight))
  201.             {
  202.                _loc3_ = Math.min(_loc3_,explicitMaxHeight);
  203.             }
  204.             if(!isNaN(explicitMinHeight))
  205.             {
  206.                _loc3_ = Math.max(_loc3_,explicitMinHeight);
  207.             }
  208.          }
  209.          else
  210.          {
  211.             _loc3_ = height;
  212.          }
  213.          if(_loc2_ != width || _loc3_ != height)
  214.          {
  215.             invalidateProperties();
  216.             invalidateSize();
  217.          }
  218.          setActualSize(_loc2_,_loc3_);
  219.          invalidateDisplayList();
  220.       }
  221.       
  222.       private function initManagers(param1:ISystemManager) : void
  223.       {
  224.          if(param1.isTopLevel())
  225.          {
  226.             focusManager = new FocusManager(this);
  227.             param1.activate(this);
  228.          }
  229.       }
  230.       
  231.       override public function initialize() : void
  232.       {
  233.          var _loc2_:Object = null;
  234.          var _loc1_:ISystemManager = systemManager;
  235.          mx_internal::_url = _loc1_.loaderInfo.url;
  236.          mx_internal::_parameters = _loc1_.loaderInfo.parameters;
  237.          initManagers(_loc1_);
  238.          mx_internal::_descriptor = null;
  239.          if(mx_internal::documentDescriptor)
  240.          {
  241.             creationPolicy = mx_internal::documentDescriptor.properties.creationPolicy;
  242.             if(creationPolicy == null || creationPolicy.length == 0)
  243.             {
  244.                creationPolicy = ContainerCreationPolicy.AUTO;
  245.             }
  246.             _loc2_ = mx_internal::documentDescriptor.properties;
  247.             if(_loc2_.width != null)
  248.             {
  249.                width = _loc2_.width;
  250.                delete _loc2_.width;
  251.             }
  252.             if(_loc2_.height != null)
  253.             {
  254.                height = _loc2_.height;
  255.                delete _loc2_.height;
  256.             }
  257.             mx_internal::documentDescriptor.events = null;
  258.          }
  259.          initContextMenu();
  260.          super.initialize();
  261.          addEventListener(Event.ADDED,addedHandler);
  262.          if(Boolean(_loc1_.isTopLevelRoot()) && Capabilities.isDebugger == true)
  263.          {
  264.             setInterval(debugTickler,1500);
  265.          }
  266.       }
  267.       
  268.       override public function set percentHeight(param1:Number) : void
  269.       {
  270.          super.percentHeight = param1;
  271.          invalidateDisplayList();
  272.       }
  273.       
  274.       override public function get id() : String
  275.       {
  276.          if(!super.id && this == Application.application && ExternalInterface.available)
  277.          {
  278.             return ExternalInterface.objectID;
  279.          }
  280.          return super.id;
  281.       }
  282.       
  283.       override mx_internal function setUnscaledWidth(param1:Number) : void
  284.       {
  285.          invalidateProperties();
  286.          super.mx_internal::setUnscaledWidth(param1);
  287.       }
  288.       
  289.       private function debugTickler() : void
  290.       {
  291.          var _loc1_:int = 0;
  292.       }
  293.       
  294.       private function doNextQueueItem(param1:FlexEvent = null) : void
  295.       {
  296.          processingCreationQueue = true;
  297.          Application.mx_internal::useProgressiveLayout = true;
  298.          callLater(processNextQueueItem);
  299.       }
  300.       
  301.       private function initContextMenu() : void
  302.       {
  303.          var _loc2_:String = null;
  304.          if(flexContextMenu != null)
  305.          {
  306.             if(systemManager is InteractiveObject)
  307.             {
  308.                InteractiveObject(systemManager).contextMenu = contextMenu;
  309.             }
  310.             return;
  311.          }
  312.          var _loc1_:ContextMenu = new ContextMenu();
  313.          _loc1_.hideBuiltInItems();
  314.          _loc1_.builtInItems.print = true;
  315.          if(_viewSourceURL)
  316.          {
  317.             _loc2_ = resourceManager.getString("core","viewSource");
  318.             viewSourceCMI = new ContextMenuItem(_loc2_,true);
  319.             viewSourceCMI.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT,menuItemSelectHandler);
  320.             _loc1_.customItems.push(viewSourceCMI);
  321.          }
  322.          contextMenu = _loc1_;
  323.          if(systemManager is InteractiveObject)
  324.          {
  325.             InteractiveObject(systemManager).contextMenu = _loc1_;
  326.          }
  327.       }
  328.       
  329.       private function addedHandler(param1:Event) : void
  330.       {
  331.          if(param1.target == this && creationQueue.length > 0)
  332.          {
  333.             doNextQueueItem();
  334.          }
  335.       }
  336.       
  337.       public function get viewSourceURL() : String
  338.       {
  339.          return _viewSourceURL;
  340.       }
  341.       
  342.       override mx_internal function get usePadding() : Boolean
  343.       {
  344.          return layout != ContainerLayout.ABSOLUTE;
  345.       }
  346.       
  347.       override mx_internal function setUnscaledHeight(param1:Number) : void
  348.       {
  349.          invalidateProperties();
  350.          super.mx_internal::setUnscaledHeight(param1);
  351.       }
  352.       
  353.       mx_internal function dockControlBar(param1:IUIComponent, param2:Boolean) : void
  354.       {
  355.          var controlBar:IUIComponent = param1;
  356.          var dock:Boolean = param2;
  357.          if(dock)
  358.          {
  359.             try
  360.             {
  361.                removeChild(DisplayObject(controlBar));
  362.             }
  363.             catch(e:Error)
  364.             {
  365.                return;
  366.             }
  367.             rawChildren.addChildAt(DisplayObject(controlBar),mx_internal::firstChildIndex);
  368.             setControlBar(controlBar);
  369.          }
  370.          else
  371.          {
  372.             try
  373.             {
  374.                rawChildren.removeChild(DisplayObject(controlBar));
  375.             }
  376.             catch(e:Error)
  377.             {
  378.                return;
  379.             }
  380.             setControlBar(null);
  381.             addChildAt(DisplayObject(controlBar),0);
  382.          }
  383.       }
  384.       
  385.       override public function styleChanged(param1:String) : void
  386.       {
  387.          super.styleChanged(param1);
  388.          if(param1 == "backgroundColor" && getStyle("backgroundImage") == getStyle("defaultBackgroundImage"))
  389.          {
  390.             clearStyle("backgroundImage");
  391.          }
  392.       }
  393.       
  394.       override protected function layoutChrome(param1:Number, param2:Number) : void
  395.       {
  396.          super.layoutChrome(param1,param2);
  397.          if(!mx_internal::doingLayout)
  398.          {
  399.             createBorder();
  400.          }
  401.          var _loc3_:EdgeMetrics = borderMetrics;
  402.          var _loc4_:Number = getStyle("borderThickness");
  403.          var _loc5_:EdgeMetrics = new EdgeMetrics();
  404.          _loc5_.left = _loc3_.left - _loc4_;
  405.          _loc5_.top = _loc3_.top - _loc4_;
  406.          _loc5_.right = _loc3_.right - _loc4_;
  407.          _loc5_.bottom = _loc3_.bottom - _loc4_;
  408.          if(Boolean(controlBar) && Boolean(controlBar.includeInLayout))
  409.          {
  410.             if(controlBar is IInvalidating)
  411.             {
  412.                IInvalidating(controlBar).invalidateDisplayList();
  413.             }
  414.             controlBar.setActualSize(width - (_loc5_.left + _loc5_.right),controlBar.getExplicitOrMeasuredHeight());
  415.             controlBar.move(_loc5_.left,_loc5_.top);
  416.          }
  417.       }
  418.       
  419.       protected function menuItemSelectHandler(param1:Event) : void
  420.       {
  421.          navigateToURL(new URLRequest(_viewSourceURL),"_blank");
  422.       }
  423.       
  424.       private function printCreationQueue() : void
  425.       {
  426.          var _loc4_:Object = null;
  427.          var _loc1_:String = "";
  428.          var _loc2_:Number = creationQueue.length;
  429.          var _loc3_:int = 0;
  430.          while(_loc3_ < _loc2_)
  431.          {
  432.             _loc4_ = creationQueue[_loc3_];
  433.             _loc1_ += " [" + _loc3_ + "] " + _loc4_.id + " " + _loc4_.index;
  434.             _loc3_++;
  435.          }
  436.       }
  437.       
  438.       override protected function resourcesChanged() : void
  439.       {
  440.          super.resourcesChanged();
  441.          if(viewSourceCMI)
  442.          {
  443.             viewSourceCMI.caption = resourceManager.getString("core","viewSource");
  444.          }
  445.       }
  446.       
  447.       override protected function commitProperties() : void
  448.       {
  449.          super.commitProperties();
  450.          resizeWidth = isNaN(explicitWidth);
  451.          resizeHeight = isNaN(explicitHeight);
  452.          if(resizeWidth || resizeHeight)
  453.          {
  454.             resizeHandler(new Event(Event.RESIZE));
  455.             if(!resizeHandlerAdded)
  456.             {
  457.                systemManager.addEventListener(Event.RESIZE,resizeHandler,false,0,true);
  458.                resizeHandlerAdded = true;
  459.             }
  460.          }
  461.          else if(resizeHandlerAdded)
  462.          {
  463.             systemManager.removeEventListener(Event.RESIZE,resizeHandler);
  464.             resizeHandlerAdded = false;
  465.          }
  466.       }
  467.       
  468.       override public function set toolTip(param1:String) : void
  469.       {
  470.       }
  471.       
  472.       public function addToCreationQueue(param1:Object, param2:int = -1, param3:Function = null, param4:IFlexDisplayObject = null) : void
  473.       {
  474.          var _loc8_:int = 0;
  475.          var _loc9_:int = 0;
  476.          var _loc10_:int = 0;
  477.          var _loc12_:int = 0;
  478.          var _loc5_:int = int(creationQueue.length);
  479.          var _loc6_:Object = {};
  480.          var _loc7_:Boolean = false;
  481.          _loc6_.id = param1;
  482.          _loc6_.parent = param4;
  483.          _loc6_.callbackFunc = param3;
  484.          _loc6_.index = param2;
  485.          var _loc11_:int = 0;
  486.          while(_loc11_ < _loc5_)
  487.          {
  488.             _loc9_ = int(creationQueue[_loc11_].index);
  489.             _loc10_ = !!creationQueue[_loc11_].parent ? int(creationQueue[_loc11_].parent.nestLevel) : 0;
  490.             if(_loc6_.index != -1)
  491.             {
  492.                if(_loc9_ == -1 || _loc6_.index < _loc9_)
  493.                {
  494.                   _loc8_ = _loc11_;
  495.                   _loc7_ = true;
  496.                   break;
  497.                }
  498.             }
  499.             else
  500.             {
  501.                _loc12_ = !!_loc6_.parent ? int(_loc6_.parent.nestLevel) : 0;
  502.                if(_loc9_ == -1 && _loc10_ < _loc12_)
  503.                {
  504.                   _loc8_ = _loc11_;
  505.                   _loc7_ = true;
  506.                   break;
  507.                }
  508.             }
  509.             _loc11_++;
  510.          }
  511.          if(!_loc7_)
  512.          {
  513.             creationQueue.push(_loc6_);
  514.             _loc7_ = true;
  515.          }
  516.          else
  517.          {
  518.             creationQueue.splice(_loc8_,0,_loc6_);
  519.          }
  520.          if(initialized && !processingCreationQueue)
  521.          {
  522.             doNextQueueItem();
  523.          }
  524.       }
  525.       
  526.       override mx_internal function initThemeColor() : Boolean
  527.       {
  528.          var _loc2_:Object = null;
  529.          var _loc3_:Number = NaN;
  530.          var _loc4_:Number = NaN;
  531.          var _loc5_:CSSStyleDeclaration = null;
  532.          var _loc1_:Boolean = super.mx_internal::initThemeColor();
  533.          if(!_loc1_)
  534.          {
  535.             _loc5_ = StyleManager.getStyleDeclaration("global");
  536.             if(_loc5_)
  537.             {
  538.                _loc2_ = _loc5_.getStyle("themeColor");
  539.                _loc3_ = _loc5_.getStyle("rollOverColor");
  540.                _loc4_ = _loc5_.getStyle("selectionColor");
  541.             }
  542.             if(_loc2_ && isNaN(_loc3_) && isNaN(_loc4_))
  543.             {
  544.                mx_internal::setThemeColor(_loc2_);
  545.             }
  546.             _loc1_ = true;
  547.          }
  548.          return _loc1_;
  549.       }
  550.       
  551.       override public function finishPrint(param1:Object, param2:IFlexDisplayObject) : void
  552.       {
  553.          if(param2 == this)
  554.          {
  555.             setActualSize(param1.width,param1.height);
  556.             if(horizontalScrollBar)
  557.             {
  558.                horizontalScrollBar.visible = param1.horizontalScrollBarVisible;
  559.             }
  560.             if(verticalScrollBar)
  561.             {
  562.                verticalScrollBar.visible = param1.verticalScrollBarVisible;
  563.             }
  564.             if(whiteBox)
  565.             {
  566.                whiteBox.visible = param1.whiteBoxVisible;
  567.             }
  568.             horizontalScrollPosition = param1.horizontalScrollPosition;
  569.             verticalScrollPosition = param1.verticalScrollPosition;
  570.             updateDisplayList(unscaledWidth,unscaledHeight);
  571.          }
  572.          super.finishPrint(param1.scrollRect,param2);
  573.       }
  574.       
  575.       private function processNextQueueItem() : void
  576.       {
  577.          var queueItem:Object = null;
  578.          var nextChild:IUIComponent = null;
  579.          if(EffectManager.mx_internal::effectsPlaying.length > 0)
  580.          {
  581.             callLater(processNextQueueItem);
  582.          }
  583.          else if(creationQueue.length > 0)
  584.          {
  585.             queueItem = creationQueue.shift();
  586.             try
  587.             {
  588.                nextChild = queueItem.id is String ? document[queueItem.id] : queueItem.id;
  589.                if(nextChild is Container)
  590.                {
  591.                   Container(nextChild).createComponentsFromDescriptors(true);
  592.                }
  593.                if(nextChild is Container && Container(nextChild).creationPolicy == ContainerCreationPolicy.QUEUED)
  594.                {
  595.                   doNextQueueItem();
  596.                }
  597.                else
  598.                {
  599.                   nextChild.addEventListener("childrenCreationComplete",doNextQueueItem);
  600.                }
  601.             }
  602.             catch(e:Error)
  603.             {
  604.                processNextQueueItem();
  605.             }
  606.          }
  607.          else
  608.          {
  609.             processingCreationQueue = false;
  610.             Application.mx_internal::useProgressiveLayout = false;
  611.          }
  612.       }
  613.       
  614.       override public function set label(param1:String) : void
  615.       {
  616.       }
  617.       
  618.       public function get parameters() : Object
  619.       {
  620.          return mx_internal::_parameters;
  621.       }
  622.       
  623.       override public function get viewMetrics() : EdgeMetrics
  624.       {
  625.          if(!_applicationViewMetrics)
  626.          {
  627.             _applicationViewMetrics = new EdgeMetrics();
  628.          }
  629.          var _loc1_:EdgeMetrics = _applicationViewMetrics;
  630.          var _loc2_:EdgeMetrics = super.viewMetrics;
  631.          var _loc3_:Number = getStyle("borderThickness");
  632.          _loc1_.left = _loc2_.left;
  633.          _loc1_.top = _loc2_.top;
  634.          _loc1_.right = _loc2_.right;
  635.          _loc1_.bottom = _loc2_.bottom;
  636.          if(Boolean(controlBar) && Boolean(controlBar.includeInLayout))
  637.          {
  638.             _loc1_.top -= _loc3_;
  639.             _loc1_.top += Math.max(controlBar.getExplicitOrMeasuredHeight(),_loc3_);
  640.          }
  641.          return _loc1_;
  642.       }
  643.       
  644.       public function get url() : String
  645.       {
  646.          return mx_internal::_url;
  647.       }
  648.       
  649.       override public function set icon(param1:Class) : void
  650.       {
  651.       }
  652.       
  653.       override protected function updateDisplayList(param1:Number, param2:Number) : void
  654.       {
  655.          super.updateDisplayList(param1,param2);
  656.          createBorder();
  657.       }
  658.       
  659.       private function setControlBar(param1:IUIComponent) : void
  660.       {
  661.          if(param1 == controlBar)
  662.          {
  663.             return;
  664.          }
  665.          if(Boolean(controlBar) && controlBar is IStyleClient)
  666.          {
  667.             IStyleClient(controlBar).clearStyle("cornerRadius");
  668.             IStyleClient(controlBar).clearStyle("docked");
  669.          }
  670.          controlBar = param1;
  671.          if(Boolean(controlBar) && controlBar is IStyleClient)
  672.          {
  673.             IStyleClient(controlBar).setStyle("cornerRadius",0);
  674.             IStyleClient(controlBar).setStyle("docked",true);
  675.          }
  676.          invalidateSize();
  677.          invalidateDisplayList();
  678.          mx_internal::invalidateViewMetricsAndPadding();
  679.       }
  680.       
  681.       override public function set tabIndex(param1:int) : void
  682.       {
  683.       }
  684.    }
  685. }
  686.  
  687.