home *** CD-ROM | disk | FTP | other *** search
/ 404 Jogos / CLJG.iso / Puzzle / filler.swf / scripts / mx / core / Application.as next >
Text File  |  2008-09-02  |  22KB  |  681 lines

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