jesterxl

SystemManager in 4.6

Jan 23rd, 2012
415
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ////////////////////////////////////////////////////////////////////////////////
  2. //
  3. //  ADOBE SYSTEMS INCORPORATED
  4. //  Copyright 2003-2007 Adobe Systems Incorporated
  5. //  All Rights Reserved.
  6. //
  7. //  NOTICE: Adobe permits you to use, modify, and distribute this file
  8. //  in accordance with the terms of the license agreement accompanying it.
  9. //
  10. ////////////////////////////////////////////////////////////////////////////////
  11.  
  12. package mx.managers
  13. {
  14.  
  15. import flash.display.DisplayObject;
  16. import flash.display.DisplayObjectContainer;
  17. import flash.display.Graphics;
  18. import flash.display.Loader;
  19. import flash.display.LoaderInfo;
  20. import flash.display.MovieClip;
  21. import flash.display.Sprite;
  22. import flash.display.Stage;
  23. import flash.display.StageAlign;
  24. import flash.display.StageQuality;
  25. import flash.display.StageScaleMode;
  26. import flash.events.Event;
  27. import flash.events.EventPhase;
  28. import flash.events.FocusEvent;
  29. import flash.events.KeyboardEvent;
  30. import flash.events.MouseEvent;
  31. import flash.events.TimerEvent;
  32. import flash.geom.Point;
  33. import flash.geom.Rectangle;
  34. import flash.system.ApplicationDomain;
  35. import flash.text.Font;
  36. import flash.text.TextFormat;
  37. import flash.ui.Keyboard;
  38. import flash.utils.Dictionary;
  39. import flash.utils.Timer;
  40. import flash.utils.getQualifiedClassName;
  41.  
  42. import mx.core.FlexSprite;
  43. import mx.core.IChildList;
  44. import mx.core.IFlexDisplayObject;
  45. import mx.core.IFlexModuleFactory;
  46. import mx.core.IInvalidating;
  47. import mx.core.IRawChildrenContainer;
  48. import mx.core.IUIComponent;
  49. import mx.core.RSLData;
  50. import mx.core.RSLItem;
  51. import mx.core.Singleton;
  52. import mx.core.mx_internal;
  53. import mx.events.DynamicEvent;
  54. import mx.events.FlexEvent;
  55. import mx.events.RSLEvent;
  56. import mx.events.Request;
  57. import mx.events.SandboxMouseEvent;
  58. import mx.preloaders.Preloader;
  59. import mx.utils.DensityUtil;
  60. import mx.utils.LoaderUtil;
  61.  
  62. // NOTE: Minimize the non-Flash classes you import here.
  63. // Any dependencies of SystemManager have to load in frame 1,
  64. // before the preloader, or anything else, can be displayed.
  65.  
  66. use namespace mx_internal;
  67.  
  68. //--------------------------------------
  69. //  Events
  70. //--------------------------------------
  71.  
  72. /**
  73.  *  Dispatched when the application has finished initializing
  74.  *
  75.  *  @eventType mx.events.FlexEvent.APPLICATION_COMPLETE
  76.  *  
  77.  *  @langversion 3.0
  78.  *  @playerversion Flash 9
  79.  *  @playerversion AIR 1.1
  80.  *  @productversion Flex 3
  81.  */
  82. [Event(name="applicationComplete", type="mx.events.FlexEvent")]
  83.  
  84. /**
  85.  *  Dispatched every 100 milliseconds when there has been no keyboard
  86.  *  or mouse activity for 1 second.
  87.  *
  88.  *  @eventType mx.events.FlexEvent.IDLE
  89.  *  
  90.  *  @langversion 3.0
  91.  *  @playerversion Flash 9
  92.  *  @playerversion AIR 1.1
  93.  *  @productversion Flex 3
  94.  */
  95. [Event(name="idle", type="mx.events.FlexEvent")]
  96.  
  97. /**
  98.  *  Dispatched when the Stage is resized.
  99.  *
  100.  *  @eventType flash.events.Event.RESIZE
  101.  *  
  102.  *  @langversion 3.0
  103.  *  @playerversion Flash 9
  104.  *  @playerversion AIR 1.1
  105.  *  @productversion Flex 3
  106.  */
  107. [Event(name="resize", type="flash.events.Event")]
  108.  
  109. /**
  110.  *  The SystemManager class manages an application window.
  111.  *  Every application that runs on the desktop or in a browser
  112.  *  has an area where the visuals of the application are
  113.  *  displayed.  
  114.  *  It may be a window in the operating system
  115.  *  or an area within the browser.  That area is an application window
  116.  *  and different from an instance of <code>mx.core.Application</code>, which
  117.  *  is the main, or top-level, window within an application.
  118.  *
  119.  *  <p>Every application has a SystemManager.  
  120.  *  The SystemManager sends an event if
  121.  *  the size of the application window changes (you cannot change it from
  122.  *  within the application, but only through interaction with the operating
  123.  *  system window or browser).  It parents all displayable things within the
  124.  *  application like the main mx.core.Application instance and all popups,
  125.  *  tooltips, cursors, and so on.  Any object parented by the SystemManager is
  126.  *  considered to be a top-level window, even tooltips and cursors.</p>
  127.  *
  128.  *  <p>The SystemManager also switches focus between top-level windows if there
  129.  *  are more than one IFocusManagerContainer displayed and users are interacting
  130.  *  with components within the IFocusManagerContainers.  </p>
  131.  *
  132.  *  <p>All keyboard and mouse activity that is not expressly trapped is seen by
  133.  *  the SystemManager, making it a good place to monitor activity should you need
  134.  *  to do so.</p>
  135.  *
  136.  *  <p>If an application is loaded into another application, a SystemManager
  137.  *  will still be created, but will not manage an application window,
  138.  *  depending on security and domain rules.
  139.  *  Instead, it will be the <code>content</code> of the <code>Loader</code>
  140.  *  that loaded it and simply serve as the parent of the sub-application</p>
  141.  *
  142.  *  <p>The SystemManager maintains multiple lists of children, one each for tooltips, cursors,
  143.  *  popup windows.  This is how it ensures that popup windows "float" above the main
  144.  *  application windows and that tooltips "float" above that and cursors above that.
  145.  *  If you simply examine the <code>numChildren</code> property or
  146.  *  call the <code>getChildAt()</code> method on the SystemManager, you are accessing
  147.  *  the main application window and any other windows that aren't popped up.  To get the list
  148.  *  of all windows, including popups, tooltips and cursors, use
  149.  *  the <code>rawChildren</code> property.</p>
  150.  *
  151.  *  <p>The SystemManager is the first display class created within an application.
  152.  *  It is responsible for creating an <code>mx.preloaders.Preloader</code> that displays and
  153.  *  <code>mx.preloaders.SparkDownloadProgressBar</code> while the application finishes loading,
  154.  *  then creates the <code>mx.core.Application</code> instance.</p>
  155.  *  
  156.  *  @langversion 3.0
  157.  *  @playerversion Flash 9
  158.  *  @playerversion AIR 1.1
  159.  *  @productversion Flex 3
  160.  */
  161. public class SystemManager extends MovieClip
  162.                            implements IChildList, IFlexDisplayObject,
  163.                            IFlexModuleFactory, ISystemManager
  164. {
  165.     include "../core/Version.as";
  166.  
  167.     //--------------------------------------------------------------------------
  168.     //
  169.     //  Class constants
  170.     //
  171.     //--------------------------------------------------------------------------
  172.  
  173.     /**
  174.      *  @private
  175.      *  The number of milliseconds that must pass without any user activity
  176.      *  before SystemManager starts dispatching 'idle' events.
  177.      */
  178.     private static const IDLE_THRESHOLD:Number = 1000;
  179.  
  180.     /**
  181.      *  @private
  182.      *  The number of milliseconds between each 'idle' event.
  183.      */
  184.     private static const IDLE_INTERVAL:Number = 100;
  185.  
  186.     //--------------------------------------------------------------------------
  187.     //
  188.     //  Class variables
  189.     //
  190.     //--------------------------------------------------------------------------
  191.  
  192.     /**
  193.      *  @private
  194.      *  An array of SystemManager instances loaded as child app domains
  195.      */
  196.     mx_internal static var allSystemManagers:Dictionary = new Dictionary(true);
  197.  
  198.     //--------------------------------------------------------------------------
  199.     //
  200.     //  Constructor
  201.     //
  202.     //--------------------------------------------------------------------------
  203.  
  204.     /**
  205.      *  Constructor.
  206.      *
  207.      *  <p>This is the starting point for all Flex applications.
  208.      *  This class is set to be the root class of a Flex SWF file.
  209.          *  Flash Player instantiates an instance of this class,
  210.      *  causing this constructor to be called.</p>
  211.      *  
  212.      *  @langversion 3.0
  213.      *  @playerversion Flash 9
  214.      *  @playerversion AIR 1.1
  215.      *  @productversion Flex 3
  216.      */
  217.     public function SystemManager()
  218.     {
  219.         CONFIG::performanceInstrumentation
  220.         {
  221.             var perfUtil:mx.utils.PerfUtil = mx.utils.PerfUtil.getInstance();
  222.             perfUtil.startSampling("Application Startup", true /*absoluteTime*/);
  223.             perfUtil.markTime("SystemManager c-tor");
  224.         }
  225.  
  226.         super();
  227.  
  228.         // Loaded SWFs don't get a stage right away
  229.         // and shouldn't override the main SWF's setting anyway.
  230.         if (stage)
  231.         {
  232.             stage.scaleMode = StageScaleMode.NO_SCALE;
  233.             stage.align = StageAlign.TOP_LEFT;
  234.             stage.quality = StageQuality.HIGH;
  235.         }
  236.  
  237.         // If we don't have a stage then we are not top-level,
  238.         // unless there are no other top-level managers, in which
  239.         // case we got loaded by a non-Flex shell or are sandboxed.
  240.         if (SystemManagerGlobals.topLevelSystemManagers.length > 0 && !stage)
  241.             topLevel = false;
  242.  
  243.         if (!stage)
  244.             isStageRoot = false;
  245.  
  246.         if (topLevel)
  247.             SystemManagerGlobals.topLevelSystemManagers.push(this);
  248.  
  249.         // Make sure to stop the playhead on the current frame.
  250.         stop();
  251.  
  252.         // Listen for the last frame (param is 0-indexed) to be executed.
  253.         //addFrameScript(totalFrames - 1, frameEndHandler);
  254.  
  255.         if (root && root.loaderInfo)
  256.             root.loaderInfo.addEventListener(Event.INIT, initHandler);
  257.            
  258.     }
  259.  
  260.    
  261.    
  262.     /**
  263.      *  @private
  264.      */
  265.     private function deferredNextFrame():void
  266.     {
  267.         if (currentFrame + 1 > totalFrames)
  268.             return;
  269.  
  270.         if (currentFrame + 1 <= framesLoaded)
  271.         {
  272.             CONFIG::performanceInstrumentation
  273.             {
  274.                 var perfUtil:mx.utils.PerfUtil = mx.utils.PerfUtil.getInstance();
  275.                 perfUtil.markTime("SystemManager.nextFrame().start");
  276.             }
  277.  
  278.             nextFrame();
  279.  
  280.             CONFIG::performanceInstrumentation
  281.             {
  282.                 perfUtil.markTime("SystemManager.nextFrame().end");
  283.             }
  284.         }
  285.         else
  286.         {
  287.             // Next frame isn't baked yet, so we'll check back...
  288.             nextFrameTimer = new Timer(100);
  289.             nextFrameTimer.addEventListener(TimerEvent.TIMER,
  290.                                             nextFrameTimerHandler);
  291.             nextFrameTimer.start();
  292.         }
  293.     }
  294.  
  295.     //--------------------------------------------------------------------------
  296.     //
  297.     //  Variables
  298.     //
  299.     //--------------------------------------------------------------------------
  300.  
  301.     /**
  302.      *  @private
  303.      *  Whether we are in the top-level list or not;
  304.      *  top-level means we are the highest level SystemManager
  305.      *  for this stage.
  306.      */
  307.     mx_internal var topLevel:Boolean = true;
  308.  
  309.     /**
  310.      *  @private
  311.      *
  312.      * true if redipatching a resize event.
  313.      */
  314.     private var isDispatchingResizeEvent:Boolean;
  315.    
  316.     /**
  317.      *  @private
  318.      *  Whether we are the stage root or not.
  319.      *  We are only the stage root if we were the root
  320.      *  of the first SWF that got loaded by the player.
  321.      *  Otherwise we could be top level but not stage root
  322.      *  if we are loaded by some other non-Flex shell
  323.      *  or are sandboxed.
  324.      */
  325.     mx_internal var isStageRoot:Boolean = true;
  326.  
  327.     /**
  328.      *  @private
  329.      *  Whether we are the first SWF loaded into a bootstrap
  330.      *  and therefore, the topLevelRoot
  331.      */
  332.     mx_internal var isBootstrapRoot:Boolean = false;
  333.  
  334.     /**
  335.      *  @private
  336.      *  If we're not top level, then we delegate many things
  337.      *  to the top level SystemManager.
  338.      */
  339.     private var _topLevelSystemManager:ISystemManager;
  340.  
  341.     /**
  342.      *  @private
  343.      *  The childAdded/removed code
  344.      */
  345.     mx_internal var childManager:ISystemManagerChildManager;
  346.  
  347.     /**
  348.      * cached value of the stage.
  349.      *  
  350.      *  @langversion 3.0
  351.      *  @playerversion Flash 9
  352.      *  @playerversion AIR 1.1
  353.      *  @productversion Flex 3
  354.      */
  355.     private var _stage:Stage;
  356.    
  357.     /**
  358.      *  Depth of this object in the containment hierarchy.
  359.      *  This number is used by the measurement and layout code.
  360.      *  
  361.      *  @langversion 3.0
  362.      *  @playerversion Flash 9
  363.      *  @playerversion AIR 1.1
  364.      *  @productversion Flex 3
  365.      */
  366.     mx_internal var nestLevel:int = 0;
  367.  
  368.     /**
  369.      *  @private
  370.      *  A reference to the preloader.
  371.      */
  372.     mx_internal var preloader:Preloader;
  373.  
  374.     /**
  375.      *  @private
  376.      *  The mouseCatcher is the 0th child of the SystemManager,
  377.      *  behind the application, which is child 1.
  378.      *  It is the same size as the stage and is filled with
  379.      *  transparent pixels; i.e., they've been drawn, but with alpha 0.
  380.      *
  381.      *  Its purpose is to make every part of the stage
  382.      *  able to detect the mouse.
  383.      *  For example, a Button puts a mouseUp handler on the SystemManager
  384.      *  in order to capture mouseUp events that occur outside the Button.
  385.      *  But if the children of the SystemManager don't have "drawn-on"
  386.      *  pixels everywhere, the player won't dispatch the mouseUp.
  387.      *  We can't simply fill the SystemManager itself with
  388.      *  transparent pixels, because the player's pixel detection
  389.      *  logic doesn't look at pixels drawn into the root DisplayObject.
  390.      *
  391.      *  Here is an example of what would happen without the mouseCatcher:
  392.      *  Run a fixed-size Application (e.g. width="600" height="600")
  393.      *  in the standalone player. Make the player window larger
  394.      *  to reveal part of the stage. Press a Button, drag off it
  395.      *  into the stage area, and release the mouse button.
  396.      *  Without the mouseCatcher, the Button wouldn't return to its "up" state.
  397.      */
  398.     private var mouseCatcher:Sprite;
  399.  
  400.     /**
  401.      *  @private
  402.      *  The top level window.
  403.      */
  404.     mx_internal var topLevelWindow:IUIComponent;
  405.  
  406.     /**
  407.      *  @private
  408.      *  Number of frames since the last mouse or key activity.
  409.      */
  410.     mx_internal var idleCounter:int = 0;
  411.  
  412.     /**
  413.      *  @private
  414.      *  The Timer used to determine when to dispatch idle events.
  415.      */
  416.     private var idleTimer:Timer;
  417.  
  418.     /**
  419.      *  @private
  420.      *  A timer used when it is necessary to wait before incrementing the frame
  421.      */
  422.     private var nextFrameTimer:Timer = null;
  423.  
  424.     /**
  425.      *  @private
  426.      *  Track which frame was last processed
  427.      */
  428.     private var lastFrame:int;
  429.  
  430.     /**
  431.      *  @private
  432.      *  A boolean as to whether we've seen COMPLETE event from preloader
  433.      */
  434.     private var readyForKickOff:Boolean;
  435.  
  436.     /**
  437.      *  @private
  438.      *
  439.      *  This variable exists only to provide a reference to this
  440.      *  app's resource bundles. This application is opting
  441.      *  into referencing its own resource bundles so the
  442.      *  ResourceManager does not need to do it. This
  443.      *  arrangement keeps the ResourceManager from pinning
  444.      *  the application in memory.
  445.      *
  446.      *  If this is the main app, then this variable will be null.
  447.      *  If this is a sub-app then ResourceManagerImpl set
  448.      *  this variable to the apps resource bundles. This variable
  449.      *  is public so it is visible to ResourceManagerImpl but starts
  450.      *  with an underscore to hint that it is an implementation detail
  451.      *  and should not be relied on.
  452.      */
  453.     public var _resourceBundles:Array;
  454.  
  455.     /**
  456.      *  @private
  457.      *  Array of RSLData objects that represent the list of RSLs this
  458.      *  module factory is loading. Each element of the Array is an
  459.      *  Array of RSLData.
  460.      */
  461.     private var rslDataList:Array
  462.    
  463.     //--------------------------------------------------------------------------
  464.     //
  465.     //  Overridden properties: DisplayObject
  466.     //
  467.     //--------------------------------------------------------------------------
  468.  
  469.     //----------------------------------
  470.     //  height
  471.     //----------------------------------
  472.  
  473.     /**
  474.      *  @private
  475.      */
  476.     private var _height:Number;
  477.  
  478.     /**
  479.      *  The height of this object.  For the SystemManager
  480.      *  this should always be the width of the stage unless the application was loaded
  481.      *  into another application.  If the application was not loaded
  482.      *  into another application, setting this value has no effect.
  483.      *  
  484.      *  @langversion 3.0
  485.      *  @playerversion Flash 9
  486.      *  @playerversion AIR 1.1
  487.      *  @productversion Flex 3
  488.      */
  489.     override public function get height():Number
  490.     {
  491.         return _height;
  492.     }
  493.  
  494.     //----------------------------------
  495.     //  stage
  496.     //----------------------------------
  497.  
  498.     /**
  499.      *  @private
  500.      *  get the main stage if we're loaded into another swf in the same sandbox
  501.      */
  502.     override public function get stage():Stage
  503.     {
  504.         if (_stage)
  505.             return _stage;
  506.            
  507.         var s:Stage = super.stage;
  508.         if (s)
  509.         {
  510.             _stage = s;
  511.             return s;
  512.         }
  513.  
  514.         if (!topLevel && _topLevelSystemManager)
  515.         {
  516.             _stage = _topLevelSystemManager.stage;
  517.             return _stage;
  518.         }
  519.  
  520.         // Case for version skew, we are a top level system manager, but
  521.         // a child of the top level root system manager and we have access
  522.         // to the stage.
  523.         if (!isStageRoot && topLevel)
  524.         {
  525.             var root:DisplayObject = getTopLevelRoot();
  526.             if (root)
  527.             {
  528.                 _stage = root.stage;
  529.                 return _stage;
  530.             }
  531.         }
  532.  
  533.         return null;
  534.     }
  535.  
  536.     //----------------------------------
  537.     //  width
  538.     //----------------------------------
  539.  
  540.     /**
  541.      *  @private
  542.      */
  543.     private var _width:Number;
  544.  
  545.     /**
  546.      *  The width of this object.  For the SystemManager
  547.      *  this should always be the width of the stage unless the application was loaded
  548.      *  into another application.  If the application was not loaded
  549.      *  into another application, setting this value will have no effect.
  550.      *  
  551.      *  @langversion 3.0
  552.      *  @playerversion Flash 9
  553.      *  @playerversion AIR 1.1
  554.      *  @productversion Flex 3
  555.      */
  556.     override public function get width():Number
  557.     {
  558.         return _width;
  559.     }
  560.  
  561.     //--------------------------------------------------------------------------
  562.     //
  563.     //  Overridden properties: DisplayObjectContainer
  564.     //
  565.     //--------------------------------------------------------------------------
  566.  
  567.     //----------------------------------
  568.     //  numChildren
  569.     //----------------------------------
  570.  
  571.     /**
  572.      *  The number of non-floating windows.  This is the main application window
  573.      *  plus any other windows added to the SystemManager that are not popups,
  574.      *  tooltips or cursors.
  575.      *  
  576.      *  @langversion 3.0
  577.      *  @playerversion Flash 9
  578.      *  @playerversion AIR 1.1
  579.      *  @productversion Flex 3
  580.      */
  581.     override public function get numChildren():int
  582.     {
  583.         return noTopMostIndex - applicationIndex;
  584.     }
  585.  
  586.     //--------------------------------------------------------------------------
  587.     //
  588.     //  Properties
  589.     //
  590.     //--------------------------------------------------------------------------
  591.  
  592.     //----------------------------------
  593.     //  allowDomainsInNewRSLs
  594.     //----------------------------------
  595.    
  596.     /**
  597.      *  @private
  598.      */
  599.     private var _allowDomainsInNewRSLs:Boolean = true;
  600.    
  601.     /**
  602.      *  @inheritDoc
  603.      *
  604.      *  @langversion 3.0
  605.      *  @playerversion Flash 10.2
  606.      *  @playerversion AIR 2.6
  607.      *  @productversion Flex 4.5
  608.      */  
  609.     public function get allowDomainsInNewRSLs():Boolean
  610.     {
  611.         return _allowDomainsInNewRSLs;
  612.     }
  613.    
  614.     /**
  615.      *  @private
  616.      */
  617.     public function set allowDomainsInNewRSLs(value:Boolean):void
  618.     {
  619.         _allowDomainsInNewRSLs = value;
  620.     }
  621.    
  622.     //----------------------------------
  623.     //  allowInsecureDomainsInNewRSLs
  624.     //----------------------------------
  625.    
  626.     /**
  627.      *  @private
  628.      */
  629.     private var _allowInsecureDomainsInNewRSLs:Boolean = true;
  630.    
  631.     /**
  632.      *  @inheritDoc
  633.      *
  634.      *  @langversion 3.0
  635.      *  @playerversion Flash 10.2
  636.      *  @playerversion AIR 2.6
  637.      *  @productversion Flex 4.5
  638.      */  
  639.     public function get allowInsecureDomainsInNewRSLs():Boolean
  640.     {
  641.         return _allowInsecureDomainsInNewRSLs;
  642.     }
  643.    
  644.     /**
  645.      *  @private
  646.      */
  647.     public function set allowInsecureDomainsInNewRSLs(value:Boolean):void
  648.     {
  649.         _allowInsecureDomainsInNewRSLs = value;
  650.     }
  651.    
  652.     //----------------------------------
  653.     //  application
  654.     //----------------------------------
  655.  
  656.     /**
  657.      *  The application parented by this SystemManager.
  658.      *  SystemManagers create an instance of an Application
  659.      *  even if they are loaded into another Application.
  660.      *  Thus, this may not match mx.core.Application.application
  661.      *  if the SWF has been loaded into another application.
  662.      *  <p>Note that this property is not typed as mx.core.Application
  663.      *  because of load-time performance considerations
  664.      *  but can be coerced into an mx.core.Application.</p>
  665.      *  
  666.      *  @langversion 3.0
  667.      *  @playerversion Flash 9
  668.      *  @playerversion AIR 1.1
  669.      *  @productversion Flex 3
  670.      */
  671.     public function get application():IUIComponent
  672.     {
  673.         return IUIComponent(_document);
  674.     }
  675.  
  676.     //----------------------------------
  677.     //  applicationIndex
  678.     //----------------------------------
  679.  
  680.     /**
  681.      *  @private
  682.      *  Storage for the applicationIndex property.
  683.      */
  684.     private var _applicationIndex:int = 1;
  685.  
  686.     /**
  687.      *  @private
  688.      *  The index of the main mx.core.Application window, which is
  689.      *  effectively its z-order.
  690.      */
  691.     mx_internal function get applicationIndex():int
  692.     {
  693.         return _applicationIndex;
  694.     }
  695.  
  696.     /**
  697.      *  @private
  698.      */
  699.     mx_internal function set applicationIndex(value:int):void
  700.     {
  701.         _applicationIndex = value;
  702.     }
  703.  
  704.    
  705.     //----------------------------------
  706.     //  cursorChildren
  707.     //----------------------------------
  708.  
  709.     /**
  710.      *  @private
  711.      *  Storage for the cursorChildren property.
  712.      */
  713.     private var _cursorChildren:SystemChildrenList;
  714.  
  715.     /**
  716.      *  @inheritDoc
  717.      *  
  718.      *  @langversion 3.0
  719.      *  @playerversion Flash 9
  720.      *  @playerversion AIR 1.1
  721.      *  @productversion Flex 3
  722.      */
  723.     public function get cursorChildren():IChildList
  724.     {
  725.         if (!topLevel)
  726.             return _topLevelSystemManager.cursorChildren;
  727.  
  728.         if (!_cursorChildren)
  729.         {
  730.             _cursorChildren = new SystemChildrenList(this,
  731.                 new QName(mx_internal, "toolTipIndex"),
  732.                 new QName(mx_internal, "cursorIndex"));
  733.         }
  734.  
  735.         return _cursorChildren;
  736.     }
  737.  
  738.     //----------------------------------
  739.     //  cursorIndex
  740.     //----------------------------------
  741.  
  742.     /**
  743.      *  @private
  744.      *  Storage for the toolTipIndex property.
  745.      */
  746.     private var _cursorIndex:int = 0;
  747.  
  748.     /**
  749.      *  @private
  750.      *  The index of the highest child that is a cursor.
  751.      */
  752.     mx_internal function get cursorIndex():int
  753.     {
  754.         return _cursorIndex;
  755.     }
  756.  
  757.     /**
  758.      *  @private
  759.      */
  760.     mx_internal function set cursorIndex(value:int):void
  761.     {
  762.         var delta:int = value - _cursorIndex;
  763.         _cursorIndex = value;
  764.     }
  765.  
  766.     //----------------------------------
  767.     //  densityScale
  768.     //----------------------------------
  769.    
  770.     /**
  771.      *  @private
  772.      *  Storage for the densityScale property
  773.      */
  774.     private var _densityScale:Number = NaN;
  775.    
  776.     /**
  777.      *  The density scale factor of the application.
  778.      *
  779.      *  When density scaling is enabled, Flex applies a scale factor based on
  780.      *  the application author density and the density of the current device
  781.      *  that Flex is running on.
  782.      *
  783.      *  Returns 1.0 when there is no scaling.
  784.      *
  785.      *  @see spark.components.Application#applicationDPI
  786.      *  @see mx.core.DensityUtil
  787.      *
  788.      *  @private
  789.      */
  790.     mx_internal function get densityScale():Number
  791.     {
  792.         if (isNaN(_densityScale))
  793.         {    
  794.             var applicationDPI:Number = info()["applicationDPI"];
  795.             var runtimeDPI:Number = DensityUtil.getRuntimeDPI();
  796.             _densityScale = DensityUtil.getDPIScale(applicationDPI, runtimeDPI);
  797.             if (isNaN(_densityScale))
  798.                 _densityScale = 1;
  799.         }
  800.  
  801.         return _densityScale;
  802.     }
  803.    
  804.     //----------------------------------
  805.     //  document
  806.     //----------------------------------
  807.  
  808.     /**
  809.      *  @private
  810.      *  Storage for the document property.
  811.      */
  812.     private var _document:Object;
  813.  
  814.     /**
  815.      *  @inheritDoc
  816.      *  
  817.      *  @langversion 3.0
  818.      *  @playerversion Flash 9
  819.      *  @playerversion AIR 1.1
  820.      *  @productversion Flex 3
  821.      */
  822.     public function get document():Object
  823.     {
  824.         return _document;
  825.     }
  826.  
  827.     /**
  828.      *  @private
  829.      */
  830.     public function set document(value:Object):void
  831.     {
  832.         _document = value;
  833.     }
  834.  
  835.     //----------------------------------
  836.     //  embeddedFontList
  837.     //----------------------------------
  838.  
  839.     /**
  840.      *  @private
  841.      *  Storage for the fontList property.
  842.      */
  843.     private var _fontList:Object = null;
  844.  
  845.     /**
  846.      *  A table of embedded fonts in this application.  The
  847.      *  object is a table indexed by the font name.
  848.      *  
  849.      *  @langversion 3.0
  850.      *  @playerversion Flash 9
  851.      *  @playerversion AIR 1.1
  852.      *  @productversion Flex 3
  853.      */
  854.     public function get embeddedFontList():Object
  855.     {
  856.         if (_fontList == null)
  857.         {
  858.             _fontList = {};
  859.  
  860.             var o:Object = info()["fonts"];
  861.  
  862.             var p:String;
  863.  
  864.             for (p in o)
  865.             {
  866.                 _fontList[p] = o[p];
  867.             }
  868.  
  869.             // Top level systemManager may not be defined if SWF is loaded
  870.             // as a background image in download progress bar.
  871.             if (!topLevel && _topLevelSystemManager)                  
  872.             {
  873.                 var fl:Object = _topLevelSystemManager.embeddedFontList;
  874.                 for (p in fl)
  875.                 {
  876.                     _fontList[p] = fl[p];
  877.                 }
  878.             }
  879.         }
  880.  
  881.         return _fontList;
  882.     }
  883.  
  884.     //----------------------------------
  885.     //  explicitHeight
  886.     //----------------------------------
  887.  
  888.     /**
  889.      *  @private
  890.      */
  891.     private var _explicitHeight:Number;
  892.  
  893.     /**
  894.      *  The explicit width of this object.  For the SystemManager
  895.      *  this should always be NaN unless the application was loaded
  896.      *  into another application.  If the application was not loaded
  897.      *  into another application, setting this value has no effect.
  898.      *  
  899.      *  @langversion 3.0
  900.      *  @playerversion Flash 9
  901.      *  @playerversion AIR 1.1
  902.      *  @productversion Flex 3
  903.      */
  904.     public function get explicitHeight():Number
  905.     {
  906.         return _explicitHeight;
  907.     }
  908.  
  909.     /**
  910.      *  @private
  911.      */
  912.     public function set explicitHeight(value:Number):void
  913.     {
  914.         _explicitHeight = value;
  915.     }
  916.  
  917.     //----------------------------------
  918.     //  explicitWidth
  919.     //----------------------------------
  920.  
  921.     /**
  922.      *  @private
  923.      */
  924.     private var _explicitWidth:Number;
  925.  
  926.     /**
  927.      *  The explicit width of this object.  For the SystemManager
  928.      *  this should always be NaN unless the application was loaded
  929.      *  into another application.  If the application was not loaded
  930.      *  into another application, setting this value has no effect.
  931.      *  
  932.      *  @langversion 3.0
  933.      *  @playerversion Flash 9
  934.      *  @playerversion AIR 1.1
  935.      *  @productversion Flex 3
  936.      */
  937.     public function get explicitWidth():Number
  938.     {
  939.         return _explicitWidth;
  940.     }
  941.  
  942.     /**
  943.      *  @private
  944.      */
  945.     public function set explicitWidth(value:Number):void
  946.     {
  947.         _explicitWidth = value;
  948.     }
  949.  
  950.     //----------------------------------
  951.     //  focusPane
  952.     //----------------------------------
  953.  
  954.     /**
  955.      *  @private
  956.      */
  957.     private var _focusPane:Sprite;
  958.  
  959.     /**
  960.      *  @copy mx.core.UIComponent#focusPane
  961.      *  
  962.      *  @langversion 3.0
  963.      *  @playerversion Flash 9
  964.      *  @playerversion AIR 1.1
  965.      *  @productversion Flex 3
  966.      */
  967.     public function get focusPane():Sprite
  968.     {
  969.         return _focusPane;
  970.     }
  971.  
  972.     /**
  973.      *  @private
  974.      */
  975.     public function set focusPane(value:Sprite):void
  976.     {
  977.         if (value)
  978.         {
  979.             addChild(value);
  980.  
  981.             value.x = 0;
  982.             value.y = 0;
  983.             value.scrollRect = null;
  984.  
  985.             _focusPane = value;
  986.         }
  987.         else
  988.         {
  989.             removeChild(_focusPane);
  990.  
  991.             _focusPane = null;
  992.         }
  993.     }
  994.  
  995.     //----------------------------------
  996.     //  isProxy
  997.     //----------------------------------
  998.  
  999.     /**
  1000.      *  True if SystemManager is a proxy and not a root class
  1001.      */
  1002.     public function get isProxy():Boolean
  1003.     {
  1004.         return false;
  1005.     }
  1006.  
  1007.     //----------------------------------
  1008.     //  measuredHeight
  1009.     //----------------------------------
  1010.  
  1011.     /**
  1012.      *  The measuredHeight is the explicit or measuredHeight of
  1013.      *  the main mx.core.Application window
  1014.      *  or the starting height of the SWF if the main window
  1015.      *  has not yet been created or does not exist.
  1016.      *  
  1017.      *  @langversion 3.0
  1018.      *  @playerversion Flash 9
  1019.      *  @playerversion AIR 1.1
  1020.      *  @productversion Flex 3
  1021.      */
  1022.     public function get measuredHeight():Number
  1023.     {
  1024.         return topLevelWindow ?
  1025.                topLevelWindow.getExplicitOrMeasuredHeight() :
  1026.                loaderInfo.height;
  1027.     }
  1028.  
  1029.     //----------------------------------
  1030.     //  measuredWidth
  1031.     //----------------------------------
  1032.  
  1033.     /**
  1034.      *  The measuredWidth is the explicit or measuredWidth of
  1035.      *  the main mx.core.Application window,
  1036.      *  or the starting width of the SWF if the main window
  1037.      *  has not yet been created or does not exist.
  1038.      *  
  1039.      *  @langversion 3.0
  1040.      *  @playerversion Flash 9
  1041.      *  @playerversion AIR 1.1
  1042.      *  @productversion Flex 3
  1043.      */
  1044.     public function get measuredWidth():Number
  1045.     {
  1046.         return topLevelWindow ?
  1047.                topLevelWindow.getExplicitOrMeasuredWidth() :
  1048.                loaderInfo.width;
  1049.     }
  1050.  
  1051.     //----------------------------------
  1052.     //  noTopMostIndex
  1053.     //----------------------------------
  1054.  
  1055.     /**
  1056.      *  @private
  1057.      *  Storage for the noTopMostIndex property.
  1058.      */
  1059.     private var _noTopMostIndex:int = 0;
  1060.  
  1061.     /**
  1062.      *  @private
  1063.      *  The index of the highest child that isn't a topmost/popup window
  1064.      */
  1065.     mx_internal function get noTopMostIndex():int
  1066.     {
  1067.         return _noTopMostIndex;
  1068.     }
  1069.  
  1070.     /**
  1071.      *  @private
  1072.      */
  1073.     mx_internal function set noTopMostIndex(value:int):void
  1074.     {
  1075.         var delta:int = value - _noTopMostIndex;
  1076.         _noTopMostIndex = value;
  1077.         topMostIndex += delta;
  1078.     }
  1079.  
  1080.     //----------------------------------
  1081.     //  $numChildren
  1082.     //----------------------------------
  1083.  
  1084.     /**
  1085.      *  @private
  1086.      *  This property allows access to the Player's native implementation
  1087.      *  of the numChildren property, which can be useful since components
  1088.      *  can override numChildren and thereby hide the native implementation.
  1089.      *  Note that this "base property" is final and cannot be overridden,
  1090.      *  so you can count on it to reflect what is happening at the player level.
  1091.      */
  1092.     mx_internal final function get $numChildren():int
  1093.     {
  1094.         return super.numChildren;
  1095.     }
  1096.  
  1097.     //----------------------------------
  1098.     //  numModalWindows
  1099.     //----------------------------------
  1100.  
  1101.     /**
  1102.      *  @private
  1103.      *  Storage for the numModalWindows property.
  1104.      */
  1105.     private var _numModalWindows:int = 0;
  1106.  
  1107.     /**
  1108.      *  The number of modal windows.  Modal windows don't allow
  1109.      *  clicking in another windows which would normally
  1110.      *  activate the FocusManager in that window.  The PopUpManager
  1111.      *  modifies this count as it creates and destroys modal windows.
  1112.      *  
  1113.      *  @langversion 3.0
  1114.      *  @playerversion Flash 9
  1115.      *  @playerversion AIR 1.1
  1116.      *  @productversion Flex 3
  1117.      */
  1118.     public function get numModalWindows():int
  1119.     {
  1120.         return _numModalWindows;
  1121.     }
  1122.  
  1123.     /**
  1124.      *  @private
  1125.      */
  1126.     public function set numModalWindows(value:int):void
  1127.     {
  1128.         _numModalWindows = value;
  1129.     }
  1130.  
  1131.     //----------------------------------
  1132.     //  preloadedRSLs
  1133.     //----------------------------------
  1134.    
  1135.     /**
  1136.      *  @inheritDoc
  1137.      *  
  1138.      */
  1139.     public function  get preloadedRSLs():Dictionary
  1140.     {
  1141.         // Overridden by compiler generate code.
  1142.         return null;                
  1143.     }
  1144.    
  1145.     /**
  1146.      *  @inheritDoc
  1147.      *  
  1148.      *  @langversion 3.0
  1149.      *  @playerversion Flash 9
  1150.      *  @playerversion AIR 1.1
  1151.      *  @productversion Flex 4.5
  1152.      */
  1153.     public function addPreloadedRSL(loaderInfo:LoaderInfo, rsl:Vector.<RSLData>):void
  1154.     {
  1155.         preloadedRSLs[loaderInfo] = rsl;
  1156.         if (hasEventListener(RSLEvent.RSL_ADD_PRELOADED))
  1157.         {
  1158.             var rslEvent:RSLEvent = new RSLEvent(RSLEvent.RSL_ADD_PRELOADED);
  1159.             rslEvent.loaderInfo = loaderInfo;
  1160.             dispatchEvent(rslEvent);
  1161.         }
  1162.        
  1163.     }
  1164.    
  1165.     //----------------------------------
  1166.     //  preloaderBackgroundAlpha
  1167.     //----------------------------------
  1168.  
  1169.     /**
  1170.      *  The background alpha used by the child of the preloader.
  1171.      *  
  1172.      *  @langversion 3.0
  1173.      *  @playerversion Flash 9
  1174.      *  @playerversion AIR 1.1
  1175.      *  @productversion Flex 3
  1176.      */
  1177.     public function get preloaderBackgroundAlpha():Number
  1178.     {
  1179.         return info()["backgroundAlpha"];
  1180.     }
  1181.  
  1182.     //----------------------------------
  1183.     //  preloaderBackgroundColor
  1184.     //----------------------------------
  1185.  
  1186.     /**
  1187.      *  The background color used by the child of the preloader.
  1188.      *  
  1189.      *  @langversion 3.0
  1190.      *  @playerversion Flash 9
  1191.      *  @playerversion AIR 1.1
  1192.      *  @productversion Flex 3
  1193.      */
  1194.     public function get preloaderBackgroundColor():uint
  1195.     {
  1196.         var value:* = info()["backgroundColor"];
  1197.         if (value == undefined)
  1198.             return 0xFFFFFFFF;
  1199.         else
  1200.             return value;
  1201.     }
  1202.  
  1203.     //----------------------------------
  1204.     //  preloaderBackgroundImage
  1205.     //----------------------------------
  1206.  
  1207.     /**
  1208.      *  The background color used by the child of the preloader.
  1209.      *  
  1210.      *  @langversion 3.0
  1211.      *  @playerversion Flash 9
  1212.      *  @playerversion AIR 1.1
  1213.      *  @productversion Flex 3
  1214.      */
  1215.     public function get preloaderBackgroundImage():Object
  1216.     {
  1217.         return info()["backgroundImage"];
  1218.     }
  1219.  
  1220.     //----------------------------------
  1221.     //  preloaderBackgroundSize
  1222.     //----------------------------------
  1223.  
  1224.     /**
  1225.      *  The background size used by the child of the preloader.
  1226.      *  
  1227.      *  @langversion 3.0
  1228.      *  @playerversion Flash 9
  1229.      *  @playerversion AIR 1.1
  1230.      *  @productversion Flex 3
  1231.      */
  1232.     public function get preloaderBackgroundSize():String
  1233.     {
  1234.         return info()["backgroundSize"];
  1235.     }
  1236.  
  1237.     //----------------------------------
  1238.     //  popUpChildren
  1239.     //----------------------------------
  1240.  
  1241.     /**
  1242.      *  @private
  1243.      *  Storage for the popUpChildren property.
  1244.      */
  1245.     private var _popUpChildren:SystemChildrenList;
  1246.  
  1247.     /**
  1248.      *  @inheritDoc
  1249.      *  
  1250.      *  @langversion 3.0
  1251.      *  @playerversion Flash 9
  1252.      *  @playerversion AIR 1.1
  1253.      *  @productversion Flex 3
  1254.      */
  1255.     public function get popUpChildren():IChildList
  1256.     {
  1257.         if (!topLevel)
  1258.             return _topLevelSystemManager.popUpChildren;
  1259.  
  1260.         if (!_popUpChildren)
  1261.         {
  1262.             _popUpChildren = new SystemChildrenList(this,
  1263.                 new QName(mx_internal, "noTopMostIndex"),
  1264.                 new QName(mx_internal, "topMostIndex"));
  1265.         }
  1266.  
  1267.         return _popUpChildren;
  1268.     }
  1269.  
  1270.     //----------------------------------
  1271.     //  rawChildren
  1272.     //----------------------------------
  1273.  
  1274.     /**
  1275.      *  @private
  1276.      *  Storage for the rawChildren property.
  1277.      */
  1278.     private var _rawChildren:SystemRawChildrenList;
  1279.  
  1280.     /**
  1281.      *  @inheritDoc
  1282.      *  
  1283.      *  @langversion 3.0
  1284.      *  @playerversion Flash 9
  1285.      *  @playerversion AIR 1.1
  1286.      *  @productversion Flex 3
  1287.      */
  1288.     public function get rawChildren():IChildList
  1289.     {
  1290.         //if (!topLevel)
  1291.         //  return _topLevelSystemManager.rawChildren;
  1292.  
  1293.         if (!_rawChildren)
  1294.             _rawChildren = new SystemRawChildrenList(this);
  1295.  
  1296.         return _rawChildren;
  1297.     }
  1298.  
  1299.     //--------------------------------------------------------------------------
  1300.     //  screen
  1301.     //--------------------------------------------------------------------------
  1302.  
  1303.     /**
  1304.      *  @private
  1305.      *  Storage for the screen property.
  1306.      */
  1307.     mx_internal var _screen:Rectangle;
  1308.  
  1309.     /**
  1310.      *  @inheritDoc
  1311.      *  
  1312.      *  @langversion 3.0
  1313.      *  @playerversion Flash 9
  1314.      *  @playerversion AIR 1.1
  1315.      *  @productversion Flex 3
  1316.      */
  1317.     public function get screen():Rectangle
  1318.     {
  1319.         if (!_screen)
  1320.             Stage_resizeHandler();
  1321.  
  1322.         if (!isStageRoot)
  1323.         {
  1324.             Stage_resizeHandler();
  1325.         }
  1326.         return _screen;
  1327.     }
  1328.  
  1329.     //----------------------------------
  1330.     //  toolTipChildren
  1331.     //----------------------------------
  1332.  
  1333.     /**
  1334.      *  @private
  1335.      *  Storage for the toolTipChildren property.
  1336.      */
  1337.     private var _toolTipChildren:SystemChildrenList;
  1338.  
  1339.     /**
  1340.      *  @inheritDoc
  1341.      *  
  1342.      *  @langversion 3.0
  1343.      *  @playerversion Flash 9
  1344.      *  @playerversion AIR 1.1
  1345.      *  @productversion Flex 3
  1346.      */
  1347.     public function get toolTipChildren():IChildList
  1348.     {
  1349.         if (!topLevel)
  1350.             return _topLevelSystemManager.toolTipChildren;
  1351.  
  1352.         if (!_toolTipChildren)
  1353.         {
  1354.             _toolTipChildren = new SystemChildrenList(this,
  1355.                 new QName(mx_internal, "topMostIndex"),
  1356.                 new QName(mx_internal, "toolTipIndex"));
  1357.         }
  1358.  
  1359.         return _toolTipChildren;
  1360.     }
  1361.  
  1362.     //----------------------------------
  1363.     //  toolTipIndex
  1364.     //----------------------------------
  1365.  
  1366.     /**
  1367.      *  @private
  1368.      *  Storage for the toolTipIndex property.
  1369.      */
  1370.     private var _toolTipIndex:int = 0;
  1371.  
  1372.     /**
  1373.      *  @private
  1374.      *  The index of the highest child that is a tooltip
  1375.      */
  1376.     mx_internal function get toolTipIndex():int
  1377.     {
  1378.         return _toolTipIndex;
  1379.     }
  1380.  
  1381.     /**
  1382.      *  @private
  1383.      */
  1384.     mx_internal function set toolTipIndex(value:int):void
  1385.     {
  1386.         var delta:int = value - _toolTipIndex;
  1387.         _toolTipIndex = value;
  1388.         cursorIndex += delta;
  1389.     }
  1390.  
  1391.     //----------------------------------
  1392.     //  topLevelSystemManager
  1393.     //----------------------------------
  1394.  
  1395.     /**
  1396.      *  Returns the SystemManager responsible for the application window.  This will be
  1397.      *  the same SystemManager unless this application has been loaded into another
  1398.      *  application.
  1399.      *  
  1400.      *  @langversion 3.0
  1401.      *  @playerversion Flash 9
  1402.      *  @playerversion AIR 1.1
  1403.      *  @productversion Flex 3
  1404.      */
  1405.     public function get topLevelSystemManager():ISystemManager
  1406.     {
  1407.         if (topLevel)
  1408.             return this;
  1409.  
  1410.         return _topLevelSystemManager;
  1411.     }
  1412.  
  1413.     //----------------------------------
  1414.     //  topMostIndex
  1415.     //----------------------------------
  1416.  
  1417.     /**
  1418.      *  @private
  1419.      *  Storage for the topMostIndex property.
  1420.      */
  1421.     private var _topMostIndex:int = 0;
  1422.  
  1423.     /**
  1424.      *  @private
  1425.      *  The index of the highest child that is a topmost/popup window
  1426.      */
  1427.     mx_internal function get topMostIndex():int
  1428.     {
  1429.         return _topMostIndex;
  1430.     }
  1431.  
  1432.     mx_internal function set topMostIndex(value:int):void
  1433.     {
  1434.         var delta:int = value - _topMostIndex;
  1435.         _topMostIndex = value;
  1436.         toolTipIndex += delta;
  1437.     }
  1438.  
  1439.  
  1440.     //--------------------------------------------------------------------------
  1441.     //
  1442.     //  Overridden methods: EventDispatcher
  1443.     //
  1444.     //--------------------------------------------------------------------------
  1445.  
  1446.     /**
  1447.      *  @private
  1448.      *  allows marshal implementation to add events
  1449.      *  
  1450.      *  @langversion 3.0
  1451.      *  @playerversion Flash 9
  1452.      *  @playerversion AIR 1.1
  1453.      *  @productversion Flex 3
  1454.      */
  1455.     mx_internal final function $addEventListener(type:String, listener:Function,
  1456.                                               useCapture:Boolean = false,
  1457.                                               priority:int = 0,
  1458.                                               useWeakReference:Boolean = false):void
  1459.     {  
  1460.         super.addEventListener(type, listener, useCapture, priority, useWeakReference);
  1461.     }
  1462.  
  1463.     /**
  1464.      * @inheritDoc
  1465.      *  
  1466.      *  @langversion 3.0
  1467.      *  @playerversion Flash 9
  1468.      *  @playerversion AIR 1.1
  1469.      *  @productversion Flex 3
  1470.      */    
  1471.     public function get childAllowsParent():Boolean
  1472.     {
  1473.         try
  1474.         {
  1475.             return loaderInfo.childAllowsParent;
  1476.         }
  1477.         catch (error:Error)
  1478.         {
  1479.             //Error #2099: The loading object is not sufficiently loaded to provide this information.
  1480.         }
  1481.        
  1482.         return false;   // assume the worst
  1483.     }
  1484.  
  1485.     /**
  1486.      *  @copy mx.core.ISWFBridgeProvider#parentAllowsChild
  1487.      *  
  1488.      *  @langversion 3.0
  1489.      *  @playerversion Flash 9
  1490.      *  @playerversion AIR 1.1
  1491.      *  @productversion Flex 3
  1492.      */    
  1493.     public function get parentAllowsChild():Boolean
  1494.     {
  1495.         try
  1496.         {
  1497.             return loaderInfo.parentAllowsChild;
  1498.         }
  1499.         catch (error:Error)
  1500.         {
  1501.             //Error #2099: The loading object is not sufficiently loaded to provide this information.
  1502.         }
  1503.        
  1504.         return false;   // assume the worst
  1505.     }
  1506.  
  1507.     /**
  1508.      * @private
  1509.      *  Only create idle events if someone is listening.
  1510.      */
  1511.     override public function addEventListener(type:String, listener:Function,
  1512.                                               useCapture:Boolean = false,
  1513.                                               priority:int = 0,
  1514.                                               useWeakReference:Boolean = false):void
  1515.     {
  1516.         if (type == MouseEvent.MOUSE_MOVE || type == MouseEvent.MOUSE_UP || type == MouseEvent.MOUSE_DOWN
  1517.                 || type == Event.ACTIVATE || type == Event.DEACTIVATE)
  1518.         {
  1519.             // also listen to stage if allowed
  1520.             try
  1521.             {
  1522.                 if (stage)
  1523.                 {
  1524.                     // Use weak listener because we don't always know when we
  1525.                     // no longer need this listener
  1526.                     stage.addEventListener(type, stageEventHandler, false, 0, true);
  1527.                 }
  1528.             }
  1529.             catch (error:SecurityError)
  1530.             {
  1531.             }
  1532.         }
  1533.  
  1534.         if (hasEventListener("addEventListener"))
  1535.         {
  1536.             var request:DynamicEvent = new DynamicEvent("addEventListener", false, true);
  1537.             request.eventType = type;
  1538.             request.listener = listener;
  1539.             request.useCapture = useCapture;
  1540.             request.priority = priority;
  1541.             request.useWeakReference = useWeakReference;
  1542.             if (!dispatchEvent(request))
  1543.                 return;
  1544.         }
  1545.  
  1546.         if (type == SandboxMouseEvent.MOUSE_UP_SOMEWHERE)
  1547.         {
  1548.             // If someone wants this event, also listen for mouseLeave.
  1549.             // Use weak listener because we don't always know when we
  1550.             // no longer need this listener
  1551.             try
  1552.             {
  1553.                 if (stage)
  1554.                 {
  1555.                     stage.addEventListener(Event.MOUSE_LEAVE, mouseLeaveHandler, false, 0, true);
  1556.                 }
  1557.                 else
  1558.                 {
  1559.                     super.addEventListener(Event.MOUSE_LEAVE, mouseLeaveHandler, false, 0, true);
  1560.                 }
  1561.             }
  1562.             catch (error:SecurityError)
  1563.             {
  1564.                 super.addEventListener(Event.MOUSE_LEAVE, mouseLeaveHandler, false, 0, true);
  1565.             }
  1566.         }
  1567.        
  1568.         // These two events will dispatched to applications in sandboxes.
  1569.         if (type == FlexEvent.RENDER || type == FlexEvent.ENTER_FRAME)
  1570.         {
  1571.             if (type == FlexEvent.RENDER)
  1572.                 type = Event.RENDER;
  1573.             else
  1574.                 type = Event.ENTER_FRAME;
  1575.                
  1576.             try
  1577.             {
  1578.                 if (stage)
  1579.                     stage.addEventListener(type, listener, useCapture, priority, useWeakReference);
  1580.                 else
  1581.                     super.addEventListener(type, listener, useCapture, priority, useWeakReference);
  1582.             }
  1583.             catch (error:SecurityError)
  1584.             {
  1585.                 super.addEventListener(type, listener, useCapture, priority, useWeakReference);
  1586.             }
  1587.        
  1588.             if (stage && type == Event.RENDER)
  1589.                 stage.invalidate();
  1590.  
  1591.             return;
  1592.         }
  1593.  
  1594.         // When the first listener registers for 'idle' events,
  1595.         // create a Timer that will fire every IDLE_INTERVAL.
  1596.         if (type == FlexEvent.IDLE && !idleTimer)
  1597.         {
  1598.             idleTimer = new Timer(IDLE_INTERVAL);
  1599.             idleTimer.addEventListener(TimerEvent.TIMER,
  1600.                                        idleTimer_timerHandler);
  1601.             idleTimer.start();
  1602.  
  1603.             // Make sure we get all activity
  1604.             // in case someone calls stopPropagation().
  1605.             addEventListener(MouseEvent.MOUSE_MOVE, mouseMoveHandler, true);
  1606.             addEventListener(MouseEvent.MOUSE_UP, mouseUpHandler, true);
  1607.         }
  1608.  
  1609.         super.addEventListener(type, listener, useCapture, priority, useWeakReference);
  1610.     }
  1611.  
  1612.     /**
  1613.      *  @private
  1614.      */
  1615.     mx_internal final function $removeEventListener(type:String, listener:Function,
  1616.                                                  useCapture:Boolean = false):void
  1617.     {
  1618.         super.removeEventListener(type, listener, useCapture);
  1619.     }
  1620.    
  1621.     /**
  1622.      *  @private
  1623.      */
  1624.     override public function removeEventListener(type:String, listener:Function,
  1625.                                                  useCapture:Boolean = false):void
  1626.     {
  1627.         if (hasEventListener("removeEventListener"))
  1628.         {
  1629.             var request:DynamicEvent = new DynamicEvent("removeEventListener", false, true);
  1630.             request.eventType = type;
  1631.             request.listener = listener;
  1632.             request.useCapture = useCapture;
  1633.             if (!dispatchEvent(request))
  1634.                 return;
  1635.         }
  1636.  
  1637.         // These two events will dispatched to applications in sandboxes.
  1638.         if (type == FlexEvent.RENDER || type == FlexEvent.ENTER_FRAME)
  1639.         {
  1640.             if (type == FlexEvent.RENDER)
  1641.                 type = Event.RENDER;
  1642.             else
  1643.                 type = Event.ENTER_FRAME;
  1644.                
  1645.             try
  1646.             {
  1647.                 if (stage)
  1648.                     stage.removeEventListener(type, listener, useCapture);
  1649.             }
  1650.             catch (error:SecurityError)
  1651.             {
  1652.             }
  1653.             // Remove both listeners in case the system manager was added
  1654.             // or removed from the stage after the listener was added.
  1655.             super.removeEventListener(type, listener, useCapture);
  1656.        
  1657.             return;
  1658.         }
  1659.  
  1660.         // When the last listener unregisters for 'idle' events,
  1661.         // stop and release the Timer.
  1662.         if (type == FlexEvent.IDLE)
  1663.         {
  1664.             super.removeEventListener(type, listener, useCapture);
  1665.  
  1666.             if (!hasEventListener(FlexEvent.IDLE) && idleTimer)
  1667.             {
  1668.                 idleTimer.stop();
  1669.                 idleTimer = null;
  1670.  
  1671.                 removeEventListener(MouseEvent.MOUSE_MOVE, mouseMoveHandler);
  1672.                 removeEventListener(MouseEvent.MOUSE_UP, mouseUpHandler);
  1673.             }
  1674.         }
  1675.         else
  1676.         {
  1677.             super.removeEventListener(type, listener, useCapture);
  1678.         }
  1679.  
  1680.         if (type == MouseEvent.MOUSE_MOVE || type == MouseEvent.MOUSE_UP || type == MouseEvent.MOUSE_DOWN
  1681.                 || type == Event.ACTIVATE || type == Event.DEACTIVATE)
  1682.         {
  1683.             if (!hasEventListener(type))
  1684.             {
  1685.                 // also listen to stage if allowed
  1686.                 try
  1687.                 {
  1688.                     if (stage)
  1689.                     {
  1690.                         stage.removeEventListener(type, stageEventHandler, false);
  1691.                     }
  1692.                 }
  1693.                 catch (error:SecurityError)
  1694.                 {
  1695.                 }
  1696.             }
  1697.         }
  1698.  
  1699.         if (type == SandboxMouseEvent.MOUSE_UP_SOMEWHERE)
  1700.         {
  1701.             if (!hasEventListener(SandboxMouseEvent.MOUSE_UP_SOMEWHERE))
  1702.             {
  1703.                 // nobody wants this event any more for now
  1704.                 try
  1705.                 {
  1706.                     if (stage)
  1707.                     {
  1708.                         stage.removeEventListener(Event.MOUSE_LEAVE, mouseLeaveHandler);
  1709.                     }
  1710.                 }
  1711.                 catch (error:SecurityError)
  1712.                 {
  1713.                 }
  1714.                 // Remove both listeners in case the system manager was added
  1715.                 // or removed from the stage after the listener was added.
  1716.                 super.removeEventListener(Event.MOUSE_LEAVE, mouseLeaveHandler);
  1717.             }
  1718.         }
  1719.     }
  1720.  
  1721.     //--------------------------------------------------------------------------
  1722.     //
  1723.     //  Overridden methods: DisplayObjectContainer
  1724.     //
  1725.     //--------------------------------------------------------------------------
  1726.  
  1727.     /**
  1728.      *  @private
  1729.      */
  1730.     override public function addChild(child:DisplayObject):DisplayObject
  1731.     {
  1732.         var addIndex:int = numChildren;
  1733.         if (child.parent == this)
  1734.             addIndex--;
  1735.  
  1736.         return addChildAt(child, addIndex);
  1737.     }
  1738.  
  1739.     /**
  1740.      *  @private
  1741.      */
  1742.     override public function addChildAt(child:DisplayObject,
  1743.                                         index:int):DisplayObject
  1744.     {
  1745.         // Adjust the partition indexes before the
  1746.         // "added" event is dispatched.
  1747.         noTopMostIndex++;
  1748.  
  1749.         var oldParent:DisplayObjectContainer = child.parent;
  1750.         if (oldParent)
  1751.             oldParent.removeChild(child);
  1752.        
  1753.         return rawChildren_addChildAt(child, applicationIndex + index);
  1754.     }
  1755.  
  1756.     /**
  1757.      *  @private
  1758.      *
  1759.      * Used by SystemManagerProxy to add a mouse catcher as a child.
  1760.      */
  1761.     mx_internal final function $addChildAt(child:DisplayObject,
  1762.                                         index:int):DisplayObject
  1763.     {
  1764.         return super.addChildAt(child, index);
  1765.     }
  1766.  
  1767.     /**
  1768.      *  @private
  1769.      *
  1770.      *  Companion to $addChildAt.
  1771.      */
  1772.     mx_internal final function $removeChildAt(index:int):DisplayObject
  1773.     {
  1774.         return super.removeChildAt(index);
  1775.     }
  1776.  
  1777.  
  1778.     /**
  1779.      *  @private
  1780.      */
  1781.     override public function removeChild(child:DisplayObject):DisplayObject
  1782.     {
  1783.         // Adjust the partition indexes
  1784.         // before the "removed" event is dispatched.
  1785.         noTopMostIndex--;
  1786.  
  1787.         return rawChildren_removeChild(child);
  1788.     }
  1789.  
  1790.     /**
  1791.      *  @private
  1792.      */
  1793.     override public function removeChildAt(index:int):DisplayObject
  1794.     {
  1795.         // Adjust the partition indexes
  1796.         // before the "removed" event is dispatched.
  1797.         noTopMostIndex--;
  1798.  
  1799.         return rawChildren_removeChildAt(applicationIndex + index);
  1800.     }
  1801.  
  1802.     /**
  1803.      *  @private
  1804.      */
  1805.     override public function getChildAt(index:int):DisplayObject
  1806.     {
  1807.         return super.getChildAt(applicationIndex + index)
  1808.     }
  1809.  
  1810.     /**
  1811.      *  @private
  1812.      */
  1813.     override public function getChildByName(name:String):DisplayObject
  1814.     {
  1815.         return super.getChildByName(name);
  1816.     }
  1817.  
  1818.     /**
  1819.      *  @private
  1820.      */
  1821.     override public function getChildIndex(child:DisplayObject):int
  1822.     {
  1823.         return super.getChildIndex(child) - applicationIndex;
  1824.     }
  1825.  
  1826.     /**
  1827.      *  @private
  1828.      */
  1829.     override public function setChildIndex(child:DisplayObject, newIndex:int):void
  1830.     {
  1831.         super.setChildIndex(child, applicationIndex + newIndex)
  1832.     }
  1833.  
  1834.     /**
  1835.      *  @private
  1836.      */
  1837.     override public function getObjectsUnderPoint(point:Point):Array
  1838.     {
  1839.         var children:Array = [];
  1840.  
  1841.         // Get all the children that aren't tooltips and cursors.
  1842.         var n:int = topMostIndex;
  1843.         for (var i:int = 0; i < n; i++)
  1844.         {
  1845.             var child:DisplayObject = super.getChildAt(i);
  1846.             if (child is DisplayObjectContainer)
  1847.             {
  1848.                 var temp:Array =
  1849.                     DisplayObjectContainer(child).getObjectsUnderPoint(point);
  1850.  
  1851.                 if (temp)
  1852.                     children = children.concat(temp);
  1853.             }
  1854.         }
  1855.  
  1856.         return children;
  1857.     }
  1858.  
  1859.     /**
  1860.      *  @private
  1861.      */
  1862.     override public function contains(child:DisplayObject):Boolean
  1863.     {
  1864.         if (super.contains(child))
  1865.         {
  1866.             if (child.parent == this)
  1867.             {
  1868.                 var childIndex:int = super.getChildIndex(child);
  1869.                 if (childIndex < noTopMostIndex)
  1870.                     return true;
  1871.             }
  1872.             else
  1873.             {
  1874.                 for (var i:int = 0; i < noTopMostIndex; i++)
  1875.                 {
  1876.                     var myChild:DisplayObject = super.getChildAt(i);
  1877.                     if (myChild is IRawChildrenContainer)
  1878.                     {
  1879.                         if (IRawChildrenContainer(myChild).rawChildren.contains(child))
  1880.                             return true;
  1881.                     }
  1882.                     if (myChild is DisplayObjectContainer)
  1883.                     {
  1884.                         if (DisplayObjectContainer(myChild).contains(child))
  1885.                             return true;
  1886.                     }
  1887.                 }
  1888.             }
  1889.         }
  1890.         return false;
  1891.     }
  1892.  
  1893.     //--------------------------------------------------------------------------
  1894.     //
  1895.     //  Methods: IFlexModuleFactory
  1896.     //
  1897.     //--------------------------------------------------------------------------
  1898.  
  1899.     /**
  1900.      *  @private
  1901.      *  This method is overridden in the autogenerated subclass.
  1902.      *  It is part of TLF's ISWFContext interface.
  1903.      *  Although this class does not declare that it implements this interface,
  1904.      *  the autogenerated subclass does.
  1905.      */
  1906.     public function callInContext(fn:Function, thisArg:Object,
  1907.                                   argArray:Array, returns:Boolean = true):*
  1908.     {
  1909.         return undefined;
  1910.     }
  1911.  
  1912.     /**
  1913.      *  A factory method that requests an instance of a
  1914.      *  definition known to the module.
  1915.      *
  1916.      *  You can provide an optional set of parameters to let building
  1917.      *  factories change what they create based on the
  1918.      *  input. Passing null indicates that the default definition
  1919.      *  is created, if possible.
  1920.      *
  1921.      *  This method is overridden in the autogenerated subclass.
  1922.      *
  1923.      *  @param params An optional list of arguments. You can pass
  1924.      *  any number of arguments, which are then stored in an Array
  1925.      *  called <code>parameters</code>.
  1926.      *
  1927.      *  @return An instance of the module, or <code>null</code>.
  1928.      *  
  1929.      *  @langversion 3.0
  1930.      *  @playerversion Flash 9
  1931.      *  @playerversion AIR 1.1
  1932.      *  @productversion Flex 3
  1933.      */
  1934.     public function create(... params):Object
  1935.     {
  1936.         var mainClassName:String = info()["mainClassName"];
  1937.  
  1938.         if (mainClassName == null)
  1939.         {
  1940.             var url:String = loaderInfo.loaderURL;
  1941.             var dot:int = url.lastIndexOf(".");
  1942.             var slash:int = url.lastIndexOf("/");
  1943.             mainClassName = url.substring(slash + 1, dot);
  1944.         }
  1945.  
  1946.         var mainClass:Class = Class(getDefinitionByName(mainClassName));
  1947.        
  1948.         return mainClass ? new mainClass() : null;
  1949.     }
  1950.  
  1951.     /**
  1952.      *  @private
  1953.      */
  1954.     public function info():Object
  1955.     {
  1956.         return {};
  1957.     }
  1958.  
  1959.     //--------------------------------------------------------------------------
  1960.     //
  1961.     //  Methods
  1962.     //
  1963.     //--------------------------------------------------------------------------
  1964.  
  1965.     /**
  1966.      *  @private
  1967.      *  Creates an instance of the preloader, adds it as a child, and runs it.
  1968.      *  This is needed by Flash Builder. Do not modify this function.
  1969.      */
  1970.     mx_internal function initialize():void
  1971.     {
  1972.         var runtimeDPIProviderClass:Class = info()["runtimeDPIProvider"] as Class;
  1973.         if (runtimeDPIProviderClass)
  1974.             Singleton.registerClass("mx.core::RuntimeDPIProvider", runtimeDPIProviderClass);
  1975.        
  1976.         if (isStageRoot)
  1977.         {
  1978.             // TODO: Finalize scaling behavior
  1979.             Stage_resizeHandler();
  1980.             // _width = stage.stageWidth;
  1981.             // _height = stage.stageHeight;
  1982.         }
  1983.         else
  1984.         {
  1985.             _width = loaderInfo.width;
  1986.             _height = loaderInfo.height;
  1987.         }
  1988.  
  1989.         // Create an instance of the preloader and add it to the stage
  1990.         preloader = new Preloader();
  1991.  
  1992.         // Listen for preloader events
  1993.         // preloader notifes when it is ok to go to frame2
  1994.         preloader.addEventListener(FlexEvent.PRELOADER_DOC_FRAME_READY,
  1995.                                    preloader_preloaderDocFrameReadyHandler);
  1996.         // wait for a complete event.  This gives the preloader
  1997.         // a chance to load resource modules before
  1998.         // everything really gets kicked off
  1999.         preloader.addEventListener(Event.COMPLETE,
  2000.                                    preloader_completeHandler);
  2001.         // when the app is fully backed remove the preloader and show the app
  2002.         preloader.addEventListener(FlexEvent.PRELOADER_DONE,
  2003.                                    preloader_preloaderDoneHandler);
  2004.         preloader.addEventListener(RSLEvent.RSL_COMPLETE,
  2005.                                    preloader_rslCompleteHandler);
  2006.  
  2007.         // Add the preloader as a child.  Use backing variable because when loaded
  2008.         // we redirect public API to parent systemmanager
  2009.         if (!_popUpChildren)
  2010.         {
  2011.             _popUpChildren = new SystemChildrenList(
  2012.                 this, new QName(mx_internal, "noTopMostIndex"), new QName(mx_internal, "topMostIndex"));
  2013.         }
  2014.         _popUpChildren.addChild(preloader);
  2015.  
  2016.         var rsls:Array = info()["rsls"];
  2017.         var cdRsls:Array = info()["cdRsls"];
  2018.         var usePreloader:Boolean = true;
  2019.         if (info()["usePreloader"] != undefined)
  2020.             usePreloader = info()["usePreloader"];
  2021.  
  2022.         var preloaderDisplayClass:Class = info()["preloader"] as Class;
  2023.  
  2024.         // Put cross-domain RSL information in the RSL list.
  2025.         var rslItemList:Array = [];
  2026.         var n:int;
  2027.         var i:int;
  2028.         if (cdRsls && cdRsls.length > 0)
  2029.         {
  2030.             if (isTopLevel())
  2031.                 rslDataList = cdRsls;
  2032.             else
  2033.                 rslDataList = LoaderUtil.processRequiredRSLs(this, cdRsls);
  2034.            
  2035.             var normalizedURL:String = LoaderUtil.normalizeURL(this.loaderInfo);
  2036.             var crossDomainRSLItem:Class = Class(getDefinitionByName("mx.core::CrossDomainRSLItem"));
  2037.             n = rslDataList.length;
  2038.             for (i = 0; i < n; i++)
  2039.             {
  2040.                 var rslWithFailovers:Array = rslDataList[i];
  2041.  
  2042.                 // If crossDomainRSLItem is null, then this is a compiler error. It should not be null.
  2043.                 var cdNode:Object = new crossDomainRSLItem(rslWithFailovers,
  2044.                                                     normalizedURL,
  2045.                                                     this);
  2046.                 rslItemList.push(cdNode);              
  2047.             }
  2048.         }
  2049.  
  2050.         // Append RSL information in the RSL list.
  2051.         if (rsls != null && rsls.length > 0)
  2052.         {
  2053.             if (rslDataList == null)
  2054.                 rslDataList = [];
  2055.            
  2056.             if (normalizedURL == null)
  2057.                 normalizedURL = LoaderUtil.normalizeURL(this.loaderInfo);
  2058.  
  2059.             n = rsls.length;
  2060.             for (i = 0; i < n; i++)
  2061.             {
  2062.                 var node:RSLItem = new RSLItem(rsls[i].url,
  2063.                                                normalizedURL,
  2064.                                                this);
  2065.                 rslItemList.push(node);
  2066.                 rslDataList.push([new RSLData(rsls[i].url, null, null, null,
  2067.                                   false, false, "current")]);
  2068.             }
  2069.         }
  2070.  
  2071.         // They can also specify a comma-separated list of URLs
  2072.         // for resource modules to be preloaded during frame 1.
  2073.         var resourceModuleURLList:String =
  2074.             loaderInfo.parameters["resourceModuleURLs"];
  2075.         var resourceModuleURLs:Array =
  2076.             resourceModuleURLList ? resourceModuleURLList.split(",") : null;
  2077.  
  2078.         var domain:ApplicationDomain =
  2079.             !topLevel && parent is Loader ?
  2080.             Loader(parent).contentLoaderInfo.applicationDomain :
  2081.             info()["currentDomain"] as ApplicationDomain;
  2082.  
  2083.         // Initialize the preloader.
  2084.         preloader.initialize(
  2085.             usePreloader,
  2086.             preloaderDisplayClass,
  2087.             preloaderBackgroundColor,
  2088.             preloaderBackgroundAlpha,
  2089.             preloaderBackgroundImage,
  2090.             preloaderBackgroundSize,
  2091.             isStageRoot ? stage.stageWidth : loaderInfo.width,
  2092.             isStageRoot ? stage.stageHeight : loaderInfo.height,
  2093.             null,
  2094.             null,
  2095.             rslItemList,
  2096.             resourceModuleURLs,
  2097.             domain);
  2098.     }
  2099.  
  2100.     //--------------------------------------------------------------------------
  2101.     //
  2102.     //  Methods: Support for rawChildren access
  2103.     //
  2104.     //--------------------------------------------------------------------------
  2105.  
  2106.     /**
  2107.      *  @private
  2108.      */
  2109.     mx_internal function rawChildren_addChild(child:DisplayObject):DisplayObject
  2110.     {
  2111.         childManager.addingChild(child);
  2112.  
  2113.         super.addChild(child);
  2114.  
  2115.         childManager.childAdded(child); // calls child.createChildren()
  2116.  
  2117.         return child;
  2118.     }
  2119.  
  2120.     /**
  2121.      *  @private
  2122.      */
  2123.     mx_internal function rawChildren_addChildAt(child:DisplayObject,
  2124.                                                 index:int):DisplayObject
  2125.     {
  2126.         // preloader goes through here before childManager is set up
  2127.         if (childManager)
  2128.             childManager.addingChild(child);
  2129.  
  2130.         super.addChildAt(child, index);
  2131.  
  2132.         if (childManager)
  2133.             childManager.childAdded(child); // calls child.createChildren()
  2134.  
  2135.         return child;
  2136.     }
  2137.  
  2138.     /**
  2139.      *  @private
  2140.      */
  2141.     mx_internal function rawChildren_removeChild(child:DisplayObject):DisplayObject
  2142.     {
  2143.         childManager.removingChild(child);
  2144.         super.removeChild(child);
  2145.         childManager.childRemoved(child);
  2146.  
  2147.         return child;
  2148.     }
  2149.  
  2150.     /**
  2151.      *  @private
  2152.      */
  2153.     mx_internal function rawChildren_removeChildAt(index:int):DisplayObject
  2154.     {
  2155.         var child:DisplayObject = super.getChildAt(index);
  2156.  
  2157.         childManager.removingChild(child);
  2158.  
  2159.         super.removeChildAt(index);
  2160.  
  2161.         childManager.childRemoved(child);
  2162.  
  2163.         return child;
  2164.     }
  2165.  
  2166.     /**
  2167.      *  @private
  2168.      */
  2169.     mx_internal function rawChildren_getChildAt(index:int):DisplayObject
  2170.     {
  2171.         return super.getChildAt(index);
  2172.     }
  2173.  
  2174.     /**
  2175.      *  @private
  2176.      */
  2177.     mx_internal function rawChildren_getChildByName(name:String):DisplayObject
  2178.     {
  2179.         return super.getChildByName(name);
  2180.     }
  2181.  
  2182.     /**
  2183.      *  @private
  2184.      */
  2185.     mx_internal function rawChildren_getChildIndex(child:DisplayObject):int
  2186.     {
  2187.         return super.getChildIndex(child);
  2188.     }
  2189.  
  2190.     /**
  2191.      *  @private
  2192.      */
  2193.     mx_internal function rawChildren_setChildIndex(child:DisplayObject, newIndex:int):void
  2194.     {
  2195.         super.setChildIndex(child, newIndex);
  2196.     }
  2197.  
  2198.     /**
  2199.      *  @private
  2200.      */
  2201.     mx_internal function rawChildren_getObjectsUnderPoint(pt:Point):Array
  2202.     {
  2203.         return super.getObjectsUnderPoint(pt);
  2204.     }
  2205.  
  2206.     /**
  2207.      *  @private
  2208.      */
  2209.     mx_internal function rawChildren_contains(child:DisplayObject):Boolean
  2210.     {
  2211.         return super.contains(child);
  2212.     }
  2213.  
  2214.     //--------------------------------------------------------------------------
  2215.     //
  2216.     //  Methods: Security
  2217.     //
  2218.     //--------------------------------------------------------------------------
  2219.    
  2220.     /**
  2221.      *  Calls Security.allowDomain() for the SWF associated with this SystemManager
  2222.      *  plus all the SWFs assocatiated with RSLs preloaded by this SystemManager.
  2223.      *
  2224.      */  
  2225.     public function allowDomain(... domains):void
  2226.     {
  2227.         // Overridden by compiler generated code.
  2228.     }
  2229.    
  2230.     /**
  2231.      *  Calls Security.allowInsecureDomain() for the SWF associated with this SystemManager
  2232.      *  plus all the SWFs assocatiated with RSLs preloaded by this SystemManager.
  2233.      *
  2234.      */  
  2235.     public function allowInsecureDomain(... domains):void
  2236.     {
  2237.         // Overridden by compiler generated code.
  2238.     }
  2239.  
  2240.     //--------------------------------------------------------------------------
  2241.     //
  2242.     //  Methods: Measurement and Layout
  2243.     //
  2244.     //--------------------------------------------------------------------------
  2245.  
  2246.     /**
  2247.      *  A convenience method for determining whether to use the
  2248.      *  explicit or measured width.
  2249.      *
  2250.      *  @return A Number that is the <code>explicitWidth</code> if defined,
  2251.      *  or the <code>measuredWidth</code> property if not.
  2252.      *  
  2253.      *  @langversion 3.0
  2254.      *  @playerversion Flash 9
  2255.      *  @playerversion AIR 1.1
  2256.      *  @productversion Flex 3
  2257.      */
  2258.     public function getExplicitOrMeasuredWidth():Number
  2259.     {
  2260.         return !isNaN(explicitWidth) ? explicitWidth : measuredWidth;
  2261.     }
  2262.  
  2263.     /**
  2264.      *  A convenience method for determining whether to use the
  2265.      *  explicit or measured height.
  2266.      *
  2267.      *  @return A Number that is the <code>explicitHeight</code> if defined,
  2268.      *  or the <code>measuredHeight</code> property if not.
  2269.      *  
  2270.      *  @langversion 3.0
  2271.      *  @playerversion Flash 9
  2272.      *  @playerversion AIR 1.1
  2273.      *  @productversion Flex 3
  2274.      */
  2275.     public function getExplicitOrMeasuredHeight():Number
  2276.     {
  2277.         return !isNaN(explicitHeight) ? explicitHeight : measuredHeight;
  2278.     }
  2279.  
  2280.     /**
  2281.      *  Calling the <code>move()</code> method
  2282.      *  has no effect as it is directly mapped
  2283.      *  to the application window or the loader.
  2284.      *
  2285.      *  @param x The new x coordinate.
  2286.      *
  2287.      *  @param y The new y coordinate.
  2288.      *  
  2289.      *  @langversion 3.0
  2290.      *  @playerversion Flash 9
  2291.      *  @playerversion AIR 1.1
  2292.      *  @productversion Flex 3
  2293.      */
  2294.     public function move(x:Number, y:Number):void
  2295.     {
  2296.     }
  2297.  
  2298.     /**
  2299.      *  Calling the <code>setActualSize()</code> method
  2300.      *  has no effect if it is directly mapped
  2301.      *  to the application window and if it is the top-level window.
  2302.      *  Otherwise attempts to resize itself, clipping children if needed.
  2303.      *
  2304.      *  @param newWidth The new width.
  2305.      *
  2306.      *  @param newHeight The new height.
  2307.      *  
  2308.      *  @langversion 3.0
  2309.      *  @playerversion Flash 9
  2310.      *  @playerversion AIR 1.1
  2311.      *  @productversion Flex 3
  2312.      */
  2313.     public function setActualSize(newWidth:Number, newHeight:Number):void
  2314.     {
  2315.         if (isStageRoot) return;
  2316.  
  2317.         // mouseCatcher is a mask if not stage root
  2318.         // sometimes it is not in sync so we always
  2319.         // sync it up
  2320.         if (mouseCatcher)
  2321.         {
  2322.             mouseCatcher.width = newWidth;
  2323.             mouseCatcher.height = newHeight;
  2324.         }
  2325.  
  2326.         if (_width != newWidth || _height != newHeight)
  2327.         {
  2328.             _width = newWidth;
  2329.             _height = newHeight;
  2330.  
  2331.             dispatchEvent(new Event(Event.RESIZE));
  2332.         }
  2333.     }
  2334.  
  2335.  
  2336.  
  2337.     //--------------------------------------------------------------------------
  2338.     //
  2339.     //  Methods: Other
  2340.     //
  2341.     //--------------------------------------------------------------------------
  2342.  
  2343.     /**
  2344.      *  @inheritDoc
  2345.      *  
  2346.      *  @langversion 3.0
  2347.      *  @playerversion Flash 9
  2348.      *  @playerversion AIR 1.1
  2349.      *  @productversion Flex 3
  2350.      */
  2351.     public function getDefinitionByName(name:String):Object
  2352.     {
  2353.         var domain:ApplicationDomain =
  2354.             !topLevel && parent is Loader ?
  2355.             Loader(parent).contentLoaderInfo.applicationDomain :
  2356.             info()["currentDomain"] as ApplicationDomain;
  2357.  
  2358.         //trace("SysMgr.getDefinitionByName domain",domain,"currentDomain",info()["currentDomain"]);    
  2359.            
  2360.         var definition:Object;
  2361.  
  2362.         if (domain.hasDefinition(name))
  2363.         {
  2364.             definition = domain.getDefinition(name);
  2365.             //trace("SysMgr.getDefinitionByName got definition",definition,"name",name);
  2366.         }
  2367.  
  2368.         return definition;
  2369.     }
  2370.  
  2371.     /**
  2372.      *  Returns the root DisplayObject of the SWF that contains the code
  2373.      *  for the given object.
  2374.      *
  2375.      *  @param object Any Object.
  2376.      *
  2377.      *  @return The root DisplayObject
  2378.      *  
  2379.      *  @langversion 3.0
  2380.      *  @playerversion Flash 9
  2381.      *  @playerversion AIR 1.1
  2382.      *  @productversion Flex 3
  2383.      */
  2384.     public static function getSWFRoot(object:Object):DisplayObject
  2385.     {
  2386.         var className:String = getQualifiedClassName(object);
  2387.  
  2388.         for (var p:* in allSystemManagers)
  2389.         {
  2390.             var sm:ISystemManager = p as ISystemManager;
  2391.             var domain:ApplicationDomain = sm.loaderInfo.applicationDomain;
  2392.             try
  2393.             {
  2394.                 var cls:Class = Class(domain.getDefinition(className));
  2395.                 if (object is cls)
  2396.                     return sm as DisplayObject;
  2397.             }
  2398.             catch(e:Error)
  2399.             {
  2400.             }
  2401.         }
  2402.         return null;
  2403.     }
  2404.    
  2405.     /**
  2406.      *  @inheritDoc
  2407.      *  
  2408.      *  @langversion 3.0
  2409.      *  @playerversion Flash 9
  2410.      *  @playerversion AIR 1.1
  2411.      *  @productversion Flex 3
  2412.      */
  2413.     public function isTopLevel():Boolean
  2414.     {
  2415.         return topLevel;
  2416.     }
  2417.  
  2418.     /**
  2419.      * @inheritDoc
  2420.      *  
  2421.      *  @langversion 3.0
  2422.      *  @playerversion Flash 9
  2423.      *  @playerversion AIR 1.1
  2424.      *  @productversion Flex 3
  2425.      */
  2426.     public function isTopLevelRoot():Boolean
  2427.     {
  2428.         return isStageRoot || isBootstrapRoot;
  2429.     }
  2430.    
  2431.     /**
  2432.          *  Determines if the given DisplayObject is the
  2433.      *  top-level window.
  2434.      *
  2435.      *  @param object The DisplayObject to test.
  2436.      *
  2437.      *  @return <code>true</code> if the given DisplayObject is the
  2438.      *  top-level window.
  2439.      *  
  2440.      *  @langversion 3.0
  2441.      *  @playerversion Flash 9
  2442.      *  @playerversion AIR 1.1
  2443.      *  @productversion Flex 3
  2444.      */
  2445.     public function isTopLevelWindow(object:DisplayObject):Boolean
  2446.     {
  2447.         return object is IUIComponent &&
  2448.                IUIComponent(object) == topLevelWindow;
  2449.     }
  2450.  
  2451.     /**
  2452.      *  @inheritDoc
  2453.      *  
  2454.      *  @langversion 3.0
  2455.      *  @playerversion Flash 9
  2456.      *  @playerversion AIR 1.1
  2457.      *  @productversion Flex 3
  2458.      */
  2459.     public function isFontFaceEmbedded(textFormat:TextFormat):Boolean
  2460.     {
  2461.         var fontName:String = textFormat.font;
  2462.         var bold:Boolean = textFormat.bold;
  2463.         var italic:Boolean = textFormat.italic;
  2464.  
  2465.         var fontList:Array = Font.enumerateFonts();
  2466.        
  2467.         var n:int = fontList.length;
  2468.         for (var i:int = 0; i < n; i++)
  2469.         {
  2470.             var font:Font = Font(fontList[i]);
  2471.             if (font.fontName == fontName)
  2472.             {
  2473.                 var style:String = "regular";
  2474.                 if (bold && italic)
  2475.                     style = "boldItalic";
  2476.                 else if (bold)
  2477.                     style = "bold";
  2478.                 else if (italic)
  2479.                     style = "italic";
  2480.  
  2481.                 if (font.fontStyle == style)
  2482.                     return true;
  2483.             }
  2484.         }
  2485.  
  2486.         if (!fontName ||
  2487.             !embeddedFontList ||
  2488.             !embeddedFontList[fontName])
  2489.         {
  2490.             return false;
  2491.         }
  2492.  
  2493.         var info:Object = embeddedFontList[fontName];
  2494.  
  2495.         return !((bold && !info.bold) ||
  2496.                  (italic && !info.italic) ||
  2497.                  (!bold && !italic && !info.regular));
  2498.     }
  2499.  
  2500.     /**
  2501.      *  @private
  2502.      *  Makes the mouseCatcher the same size as the stage,
  2503.      *  filling it with transparent pixels.
  2504.      */
  2505.     private function resizeMouseCatcher():void
  2506.     {
  2507.         if (mouseCatcher)
  2508.         {
  2509.             try
  2510.             {
  2511.             var g:Graphics = mouseCatcher.graphics;
  2512.             var s:Rectangle = screen;
  2513.             g.clear();
  2514.             g.beginFill(0x000000, 0);
  2515.             g.drawRect(0, 0, s.width, s.height);
  2516.             g.endFill();
  2517.             }
  2518.             catch (e:SecurityError)
  2519.             {
  2520.                 // trace("resizeMouseCatcher: ignoring security error " + e);
  2521.             }
  2522.         }
  2523.     }
  2524.  
  2525.     //--------------------------------------------------------------------------
  2526.     //
  2527.     //  Event handlers
  2528.     //
  2529.     //--------------------------------------------------------------------------
  2530.  
  2531.     /**
  2532.      *  @private
  2533.      */
  2534.     private function initHandler(event:Event):void
  2535.     {
  2536.         CONFIG::performanceInstrumentation
  2537.         {
  2538.             var perfUtil:mx.utils.PerfUtil = mx.utils.PerfUtil.getInstance();
  2539.             perfUtil.markTime("SystemManager.initHandler().start");
  2540.         }
  2541.        
  2542.         // we can still be the top level root if we can access our
  2543.         // parent and get a positive response to the query or
  2544.         // or there is not a listener for the new application event
  2545.         // that SWFLoader always adds.
  2546.         if (!isStageRoot)
  2547.         {
  2548.             if (root.loaderInfo.parentAllowsChild)
  2549.             {
  2550.                 try
  2551.                 {
  2552.                     if (!parent.dispatchEvent(new Event("mx.managers.SystemManager.isBootstrapRoot", false, true)) ||
  2553.                         // use string literal to avoid link dependency on SWFBridgeEvent.BRIDGE_NEW_APPLICATION
  2554.                         !root.loaderInfo.sharedEvents.hasEventListener("bridgeNewApplication"))
  2555.                         isBootstrapRoot = true;
  2556.                 }
  2557.                 catch (e:Error)
  2558.                 {
  2559.                 }
  2560.             }
  2561.         }
  2562.  
  2563.         allSystemManagers[this] = this.loaderInfo.url;
  2564.         root.loaderInfo.removeEventListener(Event.INIT, initHandler);
  2565.  
  2566.         if (!SystemManagerGlobals.info)
  2567.             SystemManagerGlobals.info = info();
  2568.         if (!SystemManagerGlobals.parameters)
  2569.             SystemManagerGlobals.parameters = loaderInfo.parameters;
  2570.  
  2571.         var docFrame:int = (totalFrames == 1)? 0 : 1;
  2572.         addEventListener(Event.ENTER_FRAME, docFrameListener);
  2573.  
  2574.         /*
  2575.         addFrameScript(docFrame, docFrameHandler);
  2576.         for (var f:int = docFrame + 1; f < totalFrames; ++f)
  2577.         {
  2578.             addFrameScript(f, extraFrameHandler);
  2579.         }
  2580.         */
  2581.  
  2582.         initialize();
  2583.  
  2584.         CONFIG::performanceInstrumentation
  2585.         {
  2586.             perfUtil.markTime("SystemManager.initHandler().end");
  2587.         }
  2588.     }
  2589.  
  2590.     private function docFrameListener(event:Event):void
  2591.     {
  2592.         if (currentFrame == 2)
  2593.         {
  2594.             removeEventListener(Event.ENTER_FRAME, docFrameListener);
  2595.             if (totalFrames > 2)
  2596.                 addEventListener(Event.ENTER_FRAME, extraFrameListener);
  2597.  
  2598.             docFrameHandler();
  2599.         }
  2600.     }
  2601.  
  2602.     private function extraFrameListener(event:Event):void
  2603.     {
  2604.         if (lastFrame == currentFrame)
  2605.             return;
  2606.  
  2607.         lastFrame = currentFrame;
  2608.  
  2609.         if (currentFrame + 1 > totalFrames)
  2610.             removeEventListener(Event.ENTER_FRAME, extraFrameListener);
  2611.  
  2612.         extraFrameHandler();
  2613.     }
  2614.  
  2615.     /**
  2616.      *  @private
  2617.      *  Once the swf has been fully downloaded,
  2618.      *  advance the playhead to the next frame.
  2619.      *  This will cause the framescript to run, which runs frameEndHandler().
  2620.      */
  2621.     private function preloader_preloaderDocFrameReadyHandler(event:Event):void
  2622.     {
  2623.         // Advance the next frame
  2624.         preloader.removeEventListener(FlexEvent.PRELOADER_DOC_FRAME_READY,
  2625.                                       preloader_preloaderDocFrameReadyHandler);
  2626.  
  2627.         deferredNextFrame();
  2628.     }
  2629.  
  2630.     /**
  2631.      *  @private
  2632.      *  Remove the preloader and add the application as a child.
  2633.      */
  2634.     private function preloader_preloaderDoneHandler(event:Event):void
  2635.     {
  2636.         var app:IUIComponent = topLevelWindow;
  2637.  
  2638.         // Once the preloader dispatches the PRELOADER_DONE event, remove the preloader
  2639.         // and add the application as the child
  2640.         preloader.removeEventListener(FlexEvent.PRELOADER_DONE,
  2641.                                       preloader_preloaderDoneHandler);
  2642.         preloader.removeEventListener(RSLEvent.RSL_COMPLETE,
  2643.                                       preloader_rslCompleteHandler);
  2644.  
  2645.         _popUpChildren.removeChild(preloader);
  2646.         preloader = null;
  2647.  
  2648.         // Add the mouseCatcher as child 0.
  2649.         mouseCatcher = new FlexSprite();
  2650.         mouseCatcher.name = "mouseCatcher";
  2651.         // Must use addChildAt because a creationComplete handler can create a
  2652.         // dialog and insert it at 0.
  2653.         noTopMostIndex++;
  2654.         super.addChildAt(mouseCatcher, 0);  
  2655.         resizeMouseCatcher();
  2656.         if (!topLevel)
  2657.         {
  2658.             mouseCatcher.visible = false;
  2659.             mask = mouseCatcher;
  2660.         }
  2661.  
  2662.         // Add the application as child 1.
  2663.         noTopMostIndex++;
  2664.         super.addChildAt(DisplayObject(app), 1);
  2665.  
  2666.         CONFIG::performanceInstrumentation
  2667.         {
  2668.             var perfUtil:mx.utils.PerfUtil = mx.utils.PerfUtil.getInstance();
  2669.             perfUtil.markTime("APPLICATION_COMPLETE");
  2670.             perfUtil.finishSampling("Application Startup");
  2671.         }
  2672.  
  2673.         // Dispatch the applicationComplete event from the Application
  2674.         // and then agaom from the SystemManager
  2675.         // (so that loading apps know we're done).
  2676.         app.dispatchEvent(new FlexEvent(FlexEvent.APPLICATION_COMPLETE));
  2677.         dispatchEvent(new FlexEvent(FlexEvent.APPLICATION_COMPLETE));
  2678.     }
  2679.  
  2680.     /**
  2681.      *  @private
  2682.      *  The preloader has completed loading an RSL.
  2683.      */
  2684.     private function preloader_rslCompleteHandler(event:RSLEvent):void
  2685.     {
  2686.         if (!event.isResourceModule && event.loaderInfo)
  2687.         {
  2688.             var rsl:Vector.<RSLData> = Vector.<RSLData>(rslDataList[event.rslIndex]);
  2689.             var moduleFactory:IFlexModuleFactory = this;
  2690.             if (rsl && rsl[0].moduleFactory)
  2691.                 moduleFactory = rsl[0].moduleFactory;
  2692.  
  2693.             if (moduleFactory == this)
  2694.                 preloadedRSLs[event.loaderInfo] =  rsl;
  2695.             else
  2696.                 moduleFactory.addPreloadedRSL(event.loaderInfo, rsl);
  2697.         }
  2698.     }
  2699.    
  2700.     /**
  2701.      *  @private
  2702.      *  This is attached as the framescript at the end of frame 2.
  2703.      *  When this function is called, we know that the application
  2704.      *  class has been defined and read in by the Player.
  2705.      */
  2706.     mx_internal function docFrameHandler(event:Event = null):void
  2707.     {
  2708.        
  2709.         if (readyForKickOff)
  2710.             kickOff();
  2711.     }
  2712.  
  2713.     /**
  2714.      *  @private
  2715.      *  kick off if we're ready
  2716.      */
  2717.     mx_internal function preloader_completeHandler(event:Event):void
  2718.     {
  2719.         preloader.removeEventListener(Event.COMPLETE,
  2720.                                    preloader_completeHandler);
  2721.         readyForKickOff = true;
  2722.         if (currentFrame >= 2)
  2723.             kickOff();
  2724.     }  
  2725.  
  2726.     /**
  2727.      *  @private
  2728.      *  kick off
  2729.      */
  2730.     mx_internal function kickOff():void
  2731.     {
  2732.         // already been here
  2733.         if (document)
  2734.             return;
  2735.  
  2736.         CONFIG::performanceInstrumentation
  2737.         {
  2738.             var perfUtil:mx.utils.PerfUtil = mx.utils.PerfUtil.getInstance();
  2739.             perfUtil.markTime("SystemManager.kickOff().start");
  2740.         }
  2741.        
  2742.         if (!isTopLevel())
  2743.             SystemManagerGlobals.topLevelSystemManagers[0].
  2744.                 // dispatch a FocusEvent so we can pass ourselves along
  2745.                 dispatchEvent(new FocusEvent(FlexEvent.NEW_CHILD_APPLICATION, false, false, this));
  2746.  
  2747.         // Generated code will bring in EmbeddedFontRegistry
  2748.         Singleton.registerClass("mx.core::IEmbeddedFontRegistry",
  2749.                 Class(getDefinitionByName("mx.core::EmbeddedFontRegistry")));
  2750.                
  2751.         Singleton.registerClass("mx.styles::IStyleManager",
  2752.             Class(getDefinitionByName("mx.styles::StyleManagerImpl")));
  2753.        
  2754.         Singleton.registerClass("mx.styles::IStyleManager2",
  2755.             Class(getDefinitionByName("mx.styles::StyleManagerImpl")));
  2756.  
  2757.         // Register other singleton classes.
  2758.         // Note: getDefinitionByName() will return null
  2759.         // if the class can't be found.
  2760.  
  2761.         Singleton.registerClass("mx.managers::IBrowserManager",
  2762.             Class(getDefinitionByName("mx.managers::BrowserManagerImpl")));
  2763.  
  2764.         Singleton.registerClass("mx.managers::ICursorManager",
  2765.             Class(getDefinitionByName("mx.managers::CursorManagerImpl")));
  2766.  
  2767.         Singleton.registerClass("mx.managers::IHistoryManager",
  2768.             Class(getDefinitionByName("mx.managers::HistoryManagerImpl")));
  2769.  
  2770.         Singleton.registerClass("mx.managers::ILayoutManager",
  2771.             Class(getDefinitionByName("mx.managers::LayoutManager")));
  2772.  
  2773.         Singleton.registerClass("mx.managers::IPopUpManager",
  2774.             Class(getDefinitionByName("mx.managers::PopUpManagerImpl")));
  2775.  
  2776.         Singleton.registerClass("mx.managers::IToolTipManager2",
  2777.             Class(getDefinitionByName("mx.managers::ToolTipManagerImpl")));
  2778.  
  2779.         var dragManagerClass:Class = null;
  2780.                
  2781.         // Make this call to create a new instance of the DragManager singleton.
  2782.         // Try to link in the NativeDragManager first. This will allow the  
  2783.         // application to receive NativeDragEvents that originate from the
  2784.         // desktop.  If it can't be found, then we're
  2785.         // not in AIR, and it can't be linked in, so we should just work off of
  2786.         // the regular Flex DragManager.
  2787.         var dmInfo:Object = info()["useNativeDragManager"];
  2788.                  
  2789.         var useNative:Boolean = dmInfo == null ? true : String(dmInfo) == "true";
  2790.          
  2791.         if (useNative)
  2792.             dragManagerClass = Class(getDefinitionByName("mx.managers::NativeDragManagerImpl"));
  2793.    
  2794.         if (dragManagerClass == null)
  2795.             dragManagerClass = Class(getDefinitionByName("mx.managers::DragManagerImpl"));
  2796.        
  2797.         Singleton.registerClass("mx.managers::IDragManager", dragManagerClass);
  2798.  
  2799.         Singleton.registerClass("mx.core::ITextFieldFactory",
  2800.             Class(getDefinitionByName("mx.core::TextFieldFactory")));
  2801.  
  2802.         var mixinList:Array = info()["mixins"];
  2803.         if (mixinList && mixinList.length > 0)
  2804.         {
  2805.             var n:int = mixinList.length;
  2806.             for (var i:int = 0; i < n; ++i)
  2807.             {
  2808.                 CONFIG::performanceInstrumentation
  2809.                 {
  2810.                     var token:int = perfUtil.markStart();
  2811.                 }
  2812.                
  2813.                 // trace("initializing mixin " + mixinList[i]);
  2814.                 var c:Class = Class(getDefinitionByName(mixinList[i]));
  2815.                 c["init"](this);
  2816.  
  2817.                 CONFIG::performanceInstrumentation
  2818.                 {
  2819.                     perfUtil.markEnd(mixinList[i], token);
  2820.                 }
  2821.             }
  2822.         }
  2823.        
  2824.         c = Singleton.getClass("mx.managers::IActiveWindowManager");
  2825.         if (c)
  2826.         {
  2827.             registerImplementation("mx.managers::IActiveWindowManager", new c(this));
  2828.         }
  2829.  
  2830.         // depends on having IActiveWindowManager installed first
  2831.         c = Singleton.getClass("mx.managers::IMarshalSystemManager");
  2832.         if (c)
  2833.         {
  2834.             registerImplementation("mx.managers::IMarshalSystemManager", new c(this));
  2835.         }
  2836.  
  2837.         CONFIG::performanceInstrumentation
  2838.         {
  2839.             // Finish here, since initializeTopLevelWidnow is instrumented separately???
  2840.             perfUtil.markTime("SystemManager.kickOff().end");
  2841.         }
  2842.  
  2843.         initializeTopLevelWindow(null);
  2844.  
  2845.         deferredNextFrame();
  2846.     }
  2847.  
  2848.     /**
  2849.      *  @private
  2850.      *  The Flash Player dispatches KeyboardEvents with cancelable=false.
  2851.      *  We'd like to be able to use the preventDefault() method on some
  2852.      *  KeyBoard events to record the fact that they've been handled.
  2853.      *  This method stops propagation of the original event and redispatches
  2854.      *  the new one from the original event's target.
  2855.      *
  2856.      *  We're only handling a small subset of keyboard events, to
  2857.      *  avoid unnecessary copying.   Most of events in the subset are
  2858.      *  handled by both Scroller and by Spark classes like TextArea or
  2859.      *  or List that include a Scroller in their skin.
  2860.      */
  2861.     private function keyDownHandler(e:KeyboardEvent):void
  2862.     {
  2863.         if (!e.cancelable)
  2864.         {
  2865.             switch (e.keyCode)
  2866.             {
  2867.                 case Keyboard.UP:
  2868.                 case Keyboard.DOWN:
  2869.                 case Keyboard.PAGE_UP:
  2870.                 case Keyboard.PAGE_DOWN:
  2871.                 case Keyboard.HOME:
  2872.                 case Keyboard.END:
  2873.                 case Keyboard.LEFT:
  2874.                 case Keyboard.RIGHT:
  2875.                 case Keyboard.ENTER:
  2876.                 {
  2877.                     e.stopImmediatePropagation();
  2878.                     var cancelableEvent:KeyboardEvent =
  2879.                         new KeyboardEvent(e.type, e.bubbles, true, e.charCode, e.keyCode,
  2880.                                           e.keyLocation, e.ctrlKey, e.altKey, e.shiftKey)              
  2881.                     e.target.dispatchEvent(cancelableEvent);
  2882.                 }
  2883.             }
  2884.         }
  2885.     }
  2886.    
  2887.     /**
  2888.      *  @private
  2889.      *  Similar to keyDownHandler above.  We want to re-dispatch
  2890.      *  mouse events that are cancellable.  Currently we are only doing
  2891.      *  this for a few mouse events and not all of them (MOUSE_WHEEL and
  2892.      *  MOUSE_DOWN).
  2893.      */
  2894.     private function mouseEventHandler(e:MouseEvent):void
  2895.     {
  2896.         if (!e.cancelable && e.eventPhase != EventPhase.BUBBLING_PHASE)
  2897.         {
  2898.             e.stopImmediatePropagation();
  2899.             var cancelableEvent:MouseEvent = null;
  2900.             if ("clickCount" in e)
  2901.             {
  2902.                 // AIR MouseEvent. We need to use a constructor so we can
  2903.                 // pass in clickCount because it is a read-only property.
  2904.                 var mouseEventClass:Class = MouseEvent;
  2905.                
  2906.                 cancelableEvent = new mouseEventClass(e.type, e.bubbles, true, e.localX,
  2907.                                 e.localY, e.relatedObject, e.ctrlKey, e.altKey,
  2908.                                 e.shiftKey, e.buttonDown, e.delta,
  2909.                                 e["commandKey"], e["controlKey"], e["clickCount"]);
  2910.             }
  2911.             else
  2912.             {
  2913.                 cancelableEvent = new MouseEvent(e.type, e.bubbles, true, e.localX,
  2914.                                  e.localY, e.relatedObject, e.ctrlKey, e.altKey,
  2915.                                  e.shiftKey, e.buttonDown, e.delta);
  2916.             }
  2917.            
  2918.             e.target.dispatchEvent(cancelableEvent);              
  2919.         }
  2920.     }
  2921.  
  2922.     private function extraFrameHandler(event:Event = null):void
  2923.     {
  2924.         var frameList:Object = info()["frames"];
  2925.                        
  2926.         if (frameList && frameList[currentLabel])
  2927.         {
  2928.             var c:Class = Class(getDefinitionByName(frameList[currentLabel]));
  2929.             c["frame"](this);
  2930.         }
  2931.  
  2932.         deferredNextFrame();
  2933.     }
  2934.    
  2935.     /**
  2936.      *  @private
  2937.      *  
  2938.      *  @langversion 3.0
  2939.      *  @playerversion Flash 9
  2940.      *  @playerversion AIR 1.1
  2941.      *  @productversion Flex 3
  2942.      */
  2943.     private function nextFrameTimerHandler(event:TimerEvent):void
  2944.     {
  2945.         if (currentFrame + 1 <= framesLoaded)
  2946.         {
  2947.             nextFrame();
  2948.             nextFrameTimer.removeEventListener(TimerEvent.TIMER, nextFrameTimerHandler);
  2949.             // stop the timer
  2950.             nextFrameTimer.reset();
  2951.                 }
  2952.             }
  2953.    
  2954.  
  2955.     /**
  2956.      *  @private
  2957.      *  Instantiates an instance of the top level window
  2958.      *  and adds it as a child of the SystemManager.
  2959.      */
  2960.     private function initializeTopLevelWindow(event:Event):void
  2961.     {
  2962.         // This listener is intended to run before any other KeyboardEvent listeners
  2963.         // so that it can redispatch a cancelable=true copy of the event.
  2964.         if (getSandboxRoot() == this)
  2965.         {
  2966.             addEventListener(KeyboardEvent.KEY_DOWN, keyDownHandler, true, 1000);
  2967.             addEventListener(MouseEvent.MOUSE_WHEEL, mouseEventHandler, true, 1000);
  2968.             addEventListener(MouseEvent.MOUSE_DOWN, mouseEventHandler, true, 1000);
  2969.         }
  2970.         if (isTopLevelRoot() && stage)
  2971.         {
  2972.             stage.addEventListener(KeyboardEvent.KEY_DOWN, keyDownHandler, false, 1000);
  2973.             stage.addEventListener(MouseEvent.MOUSE_WHEEL, mouseEventHandler, false, 1000);
  2974.             stage.addEventListener(MouseEvent.MOUSE_DOWN, mouseEventHandler, false, 1000);
  2975.         }
  2976.        
  2977.         // Parent may be null if in another sandbox and don't have
  2978.         // access to our parent.  Add a check for this case.
  2979.         if (!parent && parentAllowsChild)
  2980.             return;
  2981.        
  2982.         if (!topLevel)
  2983.         {
  2984.             // We are not top-level and don't have a parent. This can happen
  2985.             // when the application has already been unloaded by the time
  2986.             // we get to this point.
  2987.             if (!parent)
  2988.                 return;
  2989.  
  2990.             var obj:DisplayObjectContainer = parent.parent;
  2991.  
  2992.             // if there is no grandparent at this point, we might have been removed and
  2993.             // are about to be killed so just bail.  Other code that runs after
  2994.             // this point expects us to be grandparented.  Another scenario
  2995.             // is that someone loaded us but not into a parented loader, but that
  2996.             // is not allowed.
  2997.             if (!obj)
  2998.                 return;
  2999.  
  3000.             while (obj)
  3001.             {
  3002.                 if (obj is IUIComponent)
  3003.                 {
  3004.                     var sm:ISystemManager = IUIComponent(obj).systemManager;
  3005.                     if (sm && !sm.isTopLevel())
  3006.                         sm = sm.topLevelSystemManager;
  3007.                        
  3008.                     _topLevelSystemManager = sm;
  3009.                     break;
  3010.                 }
  3011.                 obj = obj.parent;
  3012.             }
  3013.         }
  3014.  
  3015.         if (isTopLevelRoot() && stage)
  3016.             stage.addEventListener(Event.RESIZE, Stage_resizeHandler, false, 0, true);
  3017.         else if (topLevel && stage)
  3018.         {
  3019.             // listen to resizes on the sandbox root
  3020.             var sandboxRoot:DisplayObject = getSandboxRoot();
  3021.             if (sandboxRoot != this)
  3022.                 sandboxRoot.addEventListener(Event.RESIZE, Stage_resizeHandler, false, 0, true);
  3023.         }
  3024.  
  3025.         var w:Number;
  3026.         var h:Number;
  3027.  
  3028.         if (isStageRoot && stage)
  3029.         {
  3030.             // stageWidth/stageHeight may have changed between initialize() and now,
  3031.             // so refresh our _width and _height here.
  3032.  
  3033.             // TODO: finalize scaling behavior
  3034.             Stage_resizeHandler();
  3035.             //_width = stage.stageWidth;
  3036.             //_height = stage.stageHeight;
  3037.            
  3038.             // Detect and account for special case where our stage in some
  3039.             // contexts has not actually been initialized fully, as is the
  3040.             // case with IE if the window is fully obscured upon loading.
  3041.             if (_width == 0 && _height == 0 &&
  3042.                 loaderInfo.width != _width &&
  3043.                 loaderInfo.height != _height)
  3044.             {
  3045.                 _width = loaderInfo.width;
  3046.                 _height = loaderInfo.height;
  3047.             }
  3048.             w = _width;
  3049.             h = _height;
  3050.         }  
  3051.         else
  3052.         {
  3053.             w = loaderInfo.width;
  3054.             h = loaderInfo.height;
  3055.         }
  3056.  
  3057.         childManager.initializeTopLevelWindow(w, h);
  3058.     }
  3059.    
  3060.     /**
  3061.      *  listen for creationComplete" on the application
  3062.      *  if you want to perform any logic
  3063.      *  when the application has finished initializing itself.
  3064.      *  
  3065.      *  @langversion 3.0
  3066.      *  @playerversion Flash 9
  3067.      *  @playerversion AIR 1.1
  3068.      *  @productversion Flex 3
  3069.      */
  3070.     private function appCreationCompleteHandler(event:FlexEvent):void
  3071.     {
  3072.         invalidateParentSizeAndDisplayList();
  3073.     }
  3074.  
  3075.     /**
  3076.      *  Attempts to notify the parent SWFLoader that the
  3077.      *  Application's size has changed.
  3078.      *  
  3079.      *  @langversion 3.0
  3080.      *  @playerversion Flash 10
  3081.      *  @playerversion AIR 1.5
  3082.      *  @productversion Flex 4
  3083.      */
  3084.     public function invalidateParentSizeAndDisplayList():void
  3085.     {
  3086.         if (!topLevel && parent)
  3087.         {
  3088.             var obj:DisplayObjectContainer = parent.parent;
  3089.             while (obj)
  3090.             {
  3091.                 if (obj is IInvalidating)
  3092.                 {
  3093.                     IInvalidating(obj).invalidateSize();
  3094.                     IInvalidating(obj).invalidateDisplayList();
  3095.                     return;
  3096.                 }
  3097.                 obj = obj.parent;
  3098.             }
  3099.         }
  3100.  
  3101.         // re-dispatch from here so MarshallPlan mixins can see it
  3102.         dispatchEvent(new Event("invalidateParentSizeAndDisplayList"));
  3103.     }
  3104.  
  3105.     /**
  3106.      *  @private
  3107.      *  Keep track of the size and position of the stage.
  3108.      */
  3109.     private function Stage_resizeHandler(event:Event = null):void
  3110.     {  
  3111.         if (isDispatchingResizeEvent)
  3112.             return;
  3113.  
  3114.         var w:Number = 0;
  3115.         var h:Number = 0;
  3116.         var m:Number;
  3117.         var n:Number;
  3118.        
  3119.         try
  3120.         {
  3121.             m = loaderInfo.width;
  3122.             n = loaderInfo.height;
  3123.         }
  3124.         catch (error:Error)
  3125.         {
  3126.             // Error #2099: The loading object is not sufficiently loaded to provide this information.
  3127.             // We get this error because an old Event.RESIZE listener with a weak reference
  3128.             // is being called but the SWF has been unloaded.
  3129.             if (!_screen)
  3130.                 _screen = new Rectangle();
  3131.                
  3132.             return;
  3133.         }
  3134.                
  3135.         var align:String = StageAlign.TOP_LEFT;
  3136.  
  3137.         // If we don't have access to the stage, then use the size of
  3138.         // the sandbox root and align to StageAlign.TOP_LEFT.                        
  3139.         try
  3140.         {
  3141.             if (stage)
  3142.             {
  3143.                 w = stage.stageWidth;
  3144.                 h = stage.stageHeight;
  3145.                 align = stage.align;
  3146.             }
  3147.         }
  3148.         catch (error:SecurityError)
  3149.         {
  3150.             if (hasEventListener("getScreen"))
  3151.             {
  3152.                 dispatchEvent(new Event("getScreen"));
  3153.                 if (_screen)
  3154.                 {
  3155.                     w = _screen.width;
  3156.                     h = _screen.height;
  3157.                 }
  3158.             }
  3159.         }
  3160.        
  3161.         var x:Number = (m - w) / 2;
  3162.         var y:Number = (n - h) / 2;
  3163.        
  3164.         if (align == StageAlign.TOP)
  3165.         {
  3166.             y = 0;
  3167.         }
  3168.         else if (align == StageAlign.BOTTOM)
  3169.         {
  3170.             y = n - h;
  3171.         }
  3172.         else if (align == StageAlign.LEFT)
  3173.         {
  3174.             x = 0;
  3175.         }
  3176.         else if (align == StageAlign.RIGHT)
  3177.         {
  3178.             x = m - w;
  3179.         }
  3180.         else if (align == StageAlign.TOP_LEFT || align == "LT") // player bug 125020
  3181.         {
  3182.             y = 0;
  3183.             x = 0;
  3184.         }
  3185.         else if (align == StageAlign.TOP_RIGHT)
  3186.         {
  3187.             y = 0;
  3188.             x = m - w;
  3189.         }
  3190.         else if (align == StageAlign.BOTTOM_LEFT)
  3191.         {
  3192.             y = n - h;
  3193.             x = 0;
  3194.         }
  3195.         else if (align == StageAlign.BOTTOM_RIGHT)
  3196.         {
  3197.             y = n - h;
  3198.             x = m - w;
  3199.         }
  3200.        
  3201.         if (!_screen)
  3202.             _screen = new Rectangle();
  3203.         _screen.x = x;
  3204.         _screen.y = y;
  3205.         _screen.width = w;
  3206.         _screen.height = h;
  3207.  
  3208.         if (isStageRoot)
  3209.         {
  3210.             var scale:Number = densityScale;
  3211.            
  3212.             root.scaleX = root.scaleY = scale;
  3213.             _width = stage.stageWidth / scale;
  3214.             _height = stage.stageHeight / scale;
  3215.            
  3216.             // Update the screen
  3217.             _screen.x /= scale;
  3218.             _screen.y /= scale;
  3219.             _screen.width /= scale;
  3220.             _screen.height /= scale;
  3221.         }
  3222.  
  3223.         if (event)
  3224.         {
  3225.             resizeMouseCatcher();
  3226.             isDispatchingResizeEvent = true;
  3227.             dispatchEvent(event);
  3228.             isDispatchingResizeEvent = false;
  3229.         }
  3230.     }
  3231.    
  3232.     /**
  3233.      *  @private
  3234.      *
  3235.      * Get the index of an object in a given child list.
  3236.      *
  3237.      * @return index of f in childList, -1 if f is not in childList.
  3238.      */
  3239.     private static function getChildListIndex(childList:IChildList, f:Object):int
  3240.     {
  3241.         var index:int = -1;
  3242.         try
  3243.         {
  3244.             index = childList.getChildIndex(DisplayObject(f));
  3245.         }
  3246.         catch (e:ArgumentError)
  3247.         {
  3248.             // index has been preset to -1 so just continue.    
  3249.         }
  3250.        
  3251.         return index;
  3252.     }
  3253.  
  3254.     /**
  3255.      *  @private
  3256.      *  Track mouse moves in order to determine idle
  3257.      */
  3258.     private function mouseMoveHandler(event:MouseEvent):void
  3259.     {
  3260.         // Reset the idle counter.
  3261.         idleCounter = 0;
  3262.     }
  3263.  
  3264.     /**
  3265.      *  @private
  3266.      *  Track mouse moves in order to determine idle.
  3267.      */
  3268.     private function mouseUpHandler(event:MouseEvent):void
  3269.     {
  3270.         // Reset the idle counter.
  3271.         idleCounter = 0;
  3272.     }
  3273.  
  3274.     /**
  3275.      *  @private
  3276.      *  Called every IDLE_INTERVAL after the first listener
  3277.      *  registers for 'idle' events.
  3278.      *  After IDLE_THRESHOLD goes by without any user activity,
  3279.      *  we dispatch an 'idle' event.
  3280.      */
  3281.     private function idleTimer_timerHandler(event:TimerEvent):void
  3282.     {
  3283.         idleCounter++;
  3284.  
  3285.         if (idleCounter * IDLE_INTERVAL > IDLE_THRESHOLD)
  3286.             dispatchEvent(new FlexEvent(FlexEvent.IDLE));
  3287.     }
  3288.  
  3289.    
  3290.    
  3291.     // fake out mouseX/mouseY
  3292.     mx_internal var _mouseX:*;
  3293.     mx_internal var _mouseY:*;
  3294.  
  3295.  
  3296.     /**
  3297.      *  @private
  3298.      */
  3299.     override public function get mouseX():Number
  3300.     {
  3301.         if (_mouseX === undefined)
  3302.             return super.mouseX;
  3303.         return _mouseX;
  3304.     }
  3305.  
  3306.     /**
  3307.      *  @private
  3308.      */
  3309.     override public function get mouseY():Number
  3310.     {
  3311.         if (_mouseY === undefined)
  3312.             return super.mouseY;
  3313.         return _mouseY;
  3314.     }
  3315.    
  3316.    
  3317.     private function getTopLevelSystemManager(parent:DisplayObject):ISystemManager
  3318.     {
  3319.         var localRoot:DisplayObjectContainer = DisplayObjectContainer(parent.root);
  3320.         var sm:ISystemManager;
  3321.        
  3322.         // If the parent isn't rooted yet,
  3323.         // Or the root is the stage (which is the case in a second AIR window)
  3324.         // use the global system manager instance.
  3325.         if ((!localRoot || localRoot is Stage) && parent is IUIComponent)
  3326.             localRoot = DisplayObjectContainer(IUIComponent(parent).systemManager);
  3327.         if (localRoot is ISystemManager)
  3328.         {
  3329.             sm = ISystemManager(localRoot);
  3330.             if (!sm.isTopLevel())
  3331.                 sm = sm.topLevelSystemManager;
  3332.         }
  3333.  
  3334.         return sm;
  3335.     }
  3336.  
  3337.     /**
  3338.      * Override parent property to handle the case where the parent is in
  3339.      * a differnt sandbox. If the parent is in the same sandbox it is returned.
  3340.      * If the parent is in a diffent sandbox, then null is returned.
  3341.      *
  3342.      *  
  3343.      *  @langversion 3.0
  3344.      *  @playerversion Flash 9
  3345.      *  @playerversion AIR 1.1
  3346.      *  @productversion Flex 3
  3347.      */
  3348.     override public function get parent():DisplayObjectContainer
  3349.     {
  3350.         try
  3351.         {
  3352.             return super.parent;
  3353.         }  
  3354.         catch (e:SecurityError)
  3355.         {
  3356.             // trace("parent: ignoring security error");
  3357.         }
  3358.        
  3359.         return null;
  3360.     }
  3361.  
  3362.    
  3363.     /**
  3364.      *  Go up the parent chain to get the top level system manager.
  3365.      *
  3366.      *  Returns <code>null</code> if not on the display list or we don't have
  3367.      *  access to the top-level system manager.
  3368.      *  
  3369.      *  @return The root system manager.
  3370.      *  
  3371.      *  @langversion 3.0
  3372.      *  @playerversion Flash 9
  3373.      *  @playerversion AIR 1.1
  3374.      *  @productversion Flex 3
  3375.      */
  3376.     public function getTopLevelRoot():DisplayObject
  3377.     {
  3378.         // work our say up the parent chain to the root. This way we
  3379.         // don't have to rely on this object being added to the stage.
  3380.         try
  3381.         {
  3382.             var sm:ISystemManager = this;
  3383.             if (sm.topLevelSystemManager)
  3384.                 sm = sm.topLevelSystemManager;
  3385.             var parent:DisplayObject = DisplayObject(sm).parent;
  3386.             var lastParent:DisplayObject = DisplayObject(sm);
  3387.             while (parent)
  3388.             {
  3389.                 if (parent is Stage)
  3390.                     return lastParent;
  3391.                 lastParent = parent;
  3392.                 parent = parent.parent;            
  3393.             }
  3394.         }
  3395.         catch (error:SecurityError)
  3396.         {
  3397.         }      
  3398.        
  3399.         return null;
  3400.     }
  3401.  
  3402.     /**
  3403.      *  Go up the parent chain to get the top level system manager in this
  3404.      *  SecurityDomain.
  3405.      *
  3406.      *  @return The root system manager in this SecurityDomain.
  3407.      *  
  3408.      *  @langversion 3.0
  3409.      *  @playerversion Flash 9
  3410.      *  @playerversion AIR 1.1
  3411.      *  @productversion Flex 3
  3412.      */
  3413.     public function getSandboxRoot():DisplayObject
  3414.     {
  3415.         // work our say up the parent chain to the root. This way we
  3416.         // don't have to rely on this object being added to the stage.
  3417.         var sm:ISystemManager = this;
  3418.  
  3419.         try
  3420.         {
  3421.             if (sm.topLevelSystemManager)
  3422.                 sm = sm.topLevelSystemManager;
  3423.             var parent:DisplayObject = DisplayObject(sm).parent;
  3424.             if (parent is Stage)
  3425.                 return DisplayObject(sm);
  3426.             // test to see if parent is a Bootstrap
  3427.             if (parent && !parent.dispatchEvent(new Event("mx.managers.SystemManager.isBootstrapRoot", false, true)))
  3428.                 return this;
  3429.             var lastParent:DisplayObject = this;
  3430.             while (parent)
  3431.             {
  3432.                 if (parent is Stage)
  3433.                     return lastParent;
  3434.                 // test to see if parent is a Bootstrap
  3435.                 if (!parent.dispatchEvent(new Event("mx.managers.SystemManager.isBootstrapRoot", false, true)))
  3436.                     return lastParent;
  3437.                    
  3438.                 // Test if the childAllowsParent so we know there is mutual trust between
  3439.                 // the sandbox root and this sm.
  3440.                 // The parentAllowsChild is taken care of by the player because it returns null
  3441.                 // for the parent if we do not have access.
  3442.                 if (parent is Loader)
  3443.                 {
  3444.                     var loader:Loader = Loader(parent);
  3445.                     var loaderInfo:LoaderInfo = loader.contentLoaderInfo;
  3446.                     if (!loaderInfo.childAllowsParent)
  3447.                         return loaderInfo.content;
  3448.                 }
  3449.                
  3450.                 // If an object is listening for system manager request we assume it is a sandbox
  3451.                 // root. If not, don't assign lastParent to this parent because it may be a
  3452.                 // non-Flex application. We only want Flex apps to be returned as sandbox roots.
  3453.                 // use constant to avoid link dependency on InterManagerRequest.SYSTEM_MANAGER_REQUEST
  3454.  
  3455.                 if (parent.hasEventListener("systemManagerRequest"
  3456.                             ))
  3457.                 lastParent = parent;
  3458.                 parent = parent.parent;            
  3459.             }
  3460.         }
  3461.         catch (error:Error)
  3462.         {
  3463.             // Either we don't have security access to a parent or
  3464.             // the swf is unloaded and loaderInfo.childAllowsParent is throwing Error #2099.
  3465.         }      
  3466.        
  3467.         return lastParent != null ? lastParent : DisplayObject(sm);
  3468.     }
  3469.    
  3470.     /**
  3471.      * @private
  3472.      *  A map of fully-qualified interface names,
  3473.      *  such as "mx.managers::IPopUpManager",
  3474.      *  to instances,
  3475.      */
  3476.     private var implMap:Object = {};
  3477.        
  3478.     /**
  3479.      * @private
  3480.      *  Adds an interface-name-to-implementation-class mapping to the registry,
  3481.      *  if a class hasn't already been registered for the specified interface.
  3482.      *  The class must implement a getInstance() method which returns
  3483.      *  its singleton instance.
  3484.      */
  3485.     public function registerImplementation(interfaceName:String,
  3486.                                          impl:Object):void
  3487.     {
  3488.         var c:Object = implMap[interfaceName];
  3489.         if (!c)
  3490.             implMap[interfaceName] = impl;
  3491.     }
  3492.        
  3493.     /**
  3494.      * @private
  3495.      *  Returns the singleton instance of the implementation class
  3496.      *  that was registered for the specified interface,
  3497.      *  by looking up the class in the registry
  3498.      *  and calling its getInstance() method.
  3499.      *
  3500.      *  This method should not be called at static initialization time,
  3501.      *  because the factory class may not have called registerClass() yet.
  3502.      */
  3503.     public function getImplementation(interfaceName:String):Object
  3504.     {
  3505.         var c:Object = implMap[interfaceName];
  3506.         return c;
  3507.     }
  3508.  
  3509.     /**
  3510.     *  @inheritDoc
  3511.      *  
  3512.      *  @langversion 3.0
  3513.      *  @playerversion Flash 9
  3514.      *  @playerversion AIR 1.1
  3515.      *  @productversion Flex 3
  3516.      */
  3517.     public function getVisibleApplicationRect(bounds:Rectangle = null, skipToSandboxRoot:Boolean = false):Rectangle
  3518.     {
  3519.         if (hasEventListener("getVisibleApplicationRect"))
  3520.         {
  3521.             var request:Request = new Request("getVisibleApplicationRect", false, true);
  3522.             request.value = { bounds: bounds, skipToSandboxRoot: skipToSandboxRoot };
  3523.             if (!dispatchEvent(request))
  3524.                 return Rectangle(request.value);
  3525.         }
  3526.        
  3527.         if (skipToSandboxRoot && !topLevel)
  3528.             return topLevelSystemManager.getVisibleApplicationRect(bounds, skipToSandboxRoot);
  3529.        
  3530.         if (!bounds)
  3531.         {
  3532.             bounds = getBounds(DisplayObject(this));
  3533.        
  3534.             var sandboxRoot:DisplayObject = getSandboxRoot();
  3535.             var s:Rectangle = screen.clone();
  3536.             s.topLeft = sandboxRoot.localToGlobal(screen.topLeft);
  3537.             s.bottomRight = sandboxRoot.localToGlobal(screen.bottomRight);
  3538.             var pt:Point = new Point(Math.max(0, bounds.x), Math.max(0, bounds.y));
  3539.             pt = localToGlobal(pt);
  3540.             bounds.x = pt.x;
  3541.             bounds.y = pt.y;
  3542.             bounds.width = s.width;
  3543.             bounds.height = s.height;
  3544.            
  3545.             // No backwards compatibility
  3546.             // See https://bugs.adobe.com/jira/browse/SDK-31377
  3547.             // FlexVersion.compatibilityVersion >= FlexVersion.VERSION_4_6
  3548.            
  3549.             // softKeyboardRect is in global coordinates.
  3550.             // Keyboard size may change size while active. Listen for
  3551.             // SoftKeyboardEvents on the stage and call
  3552.             // getVisibleApplicationRect() to get updated visible bounds.
  3553.             var softKeyboardRect:Rectangle = stage.softKeyboardRect;
  3554.             bounds.height = bounds.height - softKeyboardRect.height;
  3555.         }
  3556.        
  3557.         if (!topLevel)
  3558.         {
  3559.             var obj:DisplayObjectContainer = parent.parent;
  3560.            
  3561.             if ("getVisibleApplicationRect" in obj)
  3562.             {
  3563.                 var visibleRect:Rectangle = obj["getVisibleApplicationRect"](true);
  3564.                 bounds = bounds.intersection(visibleRect);
  3565.             }
  3566.         }
  3567.         return bounds;
  3568.     }
  3569.  
  3570.     /**
  3571.      *  @inheritDoc
  3572.      *  
  3573.      *  @langversion 3.0
  3574.      *  @playerversion Flash 9
  3575.      *  @playerversion AIR 1.1
  3576.      *  @productversion Flex 3
  3577.      */
  3578.     public function deployMouseShields(deploy:Boolean):void
  3579.     {
  3580.         if (hasEventListener("deployMouseShields"))
  3581.         {
  3582.             var dynamicEvent:DynamicEvent = new DynamicEvent("deployMouseShields");
  3583.             dynamicEvent.deploy = deploy;
  3584.             dispatchEvent(dynamicEvent);
  3585.         }
  3586.     }
  3587.  
  3588.     /**
  3589.      *  @private
  3590.      *  dispatch certain stage events from sandbox root
  3591.      */
  3592.     private function stageEventHandler(event:Event):void
  3593.     {
  3594.         if (event.target is Stage && mouseCatcher)
  3595.         {
  3596.             // need to fix up the coordinate space before re-dispatching the mouse event  
  3597.             // to put it in the same coordinate space as the mouseCatcher since the
  3598.             // mouseCatcher may be scaled while outside of the stage, we are not
  3599.             if (event is MouseEvent)
  3600.             {
  3601.                 var mouseEvent:MouseEvent = MouseEvent(event);
  3602.                 var stagePoint:Point = new Point(mouseEvent.stageX, mouseEvent.stageY);
  3603.                 var mouesCatcherLocalPoint:Point = mouseCatcher.globalToLocal(stagePoint);
  3604.                 mouseEvent.localX = mouesCatcherLocalPoint.x;
  3605.                 mouseEvent.localY = mouesCatcherLocalPoint.y;
  3606.             }
  3607.            
  3608.             // dispatch them from mouseCatcher so capture phase listeners on
  3609.             // systemManager will work
  3610.             mouseCatcher.dispatchEvent(event);
  3611.         }
  3612.     }
  3613.  
  3614.     /**
  3615.      *  @private
  3616.      *  convert MOUSE_LEAVE to MOUSE_UP_SOMEWHERE
  3617.      */
  3618.     private function mouseLeaveHandler(event:Event):void
  3619.     {
  3620.         dispatchEvent(new SandboxMouseEvent(SandboxMouseEvent.MOUSE_UP_SOMEWHERE));
  3621.     }
  3622.  
  3623. }
  3624.  
  3625. }
Advertisement
Add Comment
Please, Sign In to add comment