/Sample/mx/managers/SystemManager.as
https://github.com/ingydotnet/yaml-oscon2009-talk · ActionScript · 5528 lines · 3054 code · 737 blank · 1737 comment · 672 complexity · 0719829e2997cf363d1a00cbfa8d0c5f MD5 · raw file
Large files are truncated click here to view the full file
- ////////////////////////////////////////////////////////////////////////////////
- //
- // ADOBE SYSTEMS INCORPORATED
- // Copyright 2003-2007 Adobe Systems Incorporated
- // All Rights Reserved.
- //
- // NOTICE: Adobe permits you to use, modify, and distribute this file
- // in accordance with the terms of the license agreement accompanying it.
- //
- ////////////////////////////////////////////////////////////////////////////////
- package mx.managers
- {
- import flash.display.DisplayObject;
- import flash.display.DisplayObjectContainer;
- import flash.display.Graphics;
- import flash.display.InteractiveObject;
- import flash.display.Loader;
- import flash.display.LoaderInfo;
- import flash.display.MovieClip;
- import flash.display.Sprite;
- import flash.display.Stage;
- import flash.display.StageAlign;
- import flash.display.StageScaleMode;
- import flash.events.Event;
- import flash.events.EventDispatcher;
- import flash.events.EventPhase;
- import flash.events.IEventDispatcher;
- import flash.events.MouseEvent;
- import flash.events.TimerEvent;
- import flash.geom.Point;
- import flash.geom.Rectangle;
- import flash.net.getClassByAlias;
- import flash.net.registerClassAlias;
- import flash.system.ApplicationDomain;
- import flash.system.Capabilities;
- import flash.text.Font;
- import flash.text.TextFormat;
- import flash.utils.ByteArray;
- import flash.utils.Dictionary;
- import flash.utils.Timer;
- import flash.utils.getQualifiedClassName;
- import mx.core.EmbeddedFontRegistry;
- import mx.core.EventPriority;
- import mx.core.FlexSprite;
- import mx.core.ISWFLoader;
- import mx.core.IChildList;
- import mx.core.IFlexDisplayObject;
- import mx.core.IFlexModuleFactory;
- import mx.core.IInvalidating;
- import mx.core.IRawChildrenContainer;
- import mx.core.ISWFBridgeGroup;
- import mx.core.ISWFBridgeProvider;
- import mx.core.IUIComponent;
- import mx.core.RSLItem;
- import mx.core.Singleton;
- import mx.core.SWFBridgeGroup;
- import mx.core.TextFieldFactory;
- import mx.core.mx_internal;
- import mx.events.FlexEvent;
- import mx.messaging.config.LoaderConfig;
- import mx.preloaders.DownloadProgressBar;
- import mx.preloaders.Preloader;
- import mx.resources.IResourceManager;
- import mx.resources.ResourceBundle;
- import mx.resources.ResourceManager;
- import mx.styles.ISimpleStyleClient;
- import mx.styles.IStyleClient;
- import mx.styles.StyleManager;
- import mx.events.EventListenerRequest;
- import mx.events.FlexChangeEvent;
- import mx.events.InvalidateRequestData;
- import mx.events.InterManagerRequest;
- import mx.events.ResizeEvent;
- import mx.events.SandboxMouseEvent;
- import mx.events.SWFBridgeRequest;
- import mx.events.SWFBridgeEvent;
- import mx.managers.systemClasses.RemotePopUp;
- import mx.managers.systemClasses.EventProxy;
- import mx.managers.systemClasses.StageEventProxy;
- import mx.managers.systemClasses.PlaceholderData;
- import mx.utils.EventUtil;
- import mx.utils.NameUtil;
- import mx.utils.LoaderUtil;
- import mx.utils.ObjectUtil;
- import mx.utils.SecurityUtil;
- // NOTE: Minimize the non-Flash classes you import here.
- // Any dependencies of SystemManager have to load in frame 1,
- // before the preloader, or anything else, can be displayed.
- use namespace mx_internal;
- //--------------------------------------
- // Events
- //--------------------------------------
- /**
- * Dispatched when the application has finished initializing
- *
- * @eventType mx.events.FlexEvent.APPLICATION_COMPLETE
- */
- [Event(name="applicationComplete", type="mx.events.FlexEvent")]
- /**
- * Dispatched every 100 milliseconds when there has been no keyboard
- * or mouse activity for 1 second.
- *
- * @eventType mx.events.FlexEvent.IDLE
- */
- [Event(name="idle", type="mx.events.FlexEvent")]
- /**
- * Dispatched when the Stage is resized.
- *
- * @eventType flash.events.Event.RESIZE
- */
- [Event(name="resize", type="flash.events.Event")]
- /**
- * The SystemManager class manages an application window.
- * Every application that runs on the desktop or in a browser
- * has an area where the visuals of the application are
- * displayed.
- * It may be a window in the operating system
- * or an area within the browser. That area is an application window
- * and different from an instance of <code>mx.core.Application</code>, which
- * is the main, or top-level, window within an application.
- *
- * <p>Every application has a SystemManager.
- * The SystemManager sends an event if
- * the size of the application window changes (you cannot change it from
- * within the application, but only through interaction with the operating
- * system window or browser). It parents all displayable things within the
- * application like the main mx.core.Application instance and all popups,
- * tooltips, cursors, and so on. Any object parented by the SystemManager is
- * considered to be a top-level window, even tooltips and cursors.</p>
- *
- * <p>The SystemManager also switches focus between top-level windows if there
- * are more than one IFocusManagerContainer displayed and users are interacting
- * with components within the IFocusManagerContainers. </p>
- *
- * <p>All keyboard and mouse activity that is not expressly trapped is seen by
- * the SystemManager, making it a good place to monitor activity should you need
- * to do so.</p>
- *
- * <p>If an application is loaded into another application, a SystemManager
- * will still be created, but will not manage an application window,
- * depending on security and domain rules.
- * Instead, it will be the <code>content</code> of the <code>Loader</code>
- * that loaded it and simply serve as the parent of the sub-application</p>
- *
- * <p>The SystemManager maintains multiple lists of children, one each for tooltips, cursors,
- * popup windows. This is how it ensures that popup windows "float" above the main
- * application windows and that tooltips "float" above that and cursors above that.
- * If you simply examine the <code>numChildren</code> property or
- * call the <code>getChildAt()</code> method on the SystemManager, you are accessing
- * the main application window and any other windows that aren't popped up. To get the list
- * of all windows, including popups, tooltips and cursors, use
- * the <code>rawChildren</code> property.</p>
- *
- * <p>The SystemManager is the first display class created within an application.
- * It is responsible for creating an <code>mx.preloaders.Preloader</code> that displays and
- * <code>mx.preloaders.DownloadProgressBar</code> while the application finishes loading,
- * then creates the <code>mx.core.Application</code> instance.</p>
- */
- public class SystemManager extends MovieClip
- implements IChildList, IFlexDisplayObject,
- IFlexModuleFactory, ISystemManager, ISWFBridgeProvider
- {
- include "../core/Version.as";
- //--------------------------------------------------------------------------
- //
- // Class constants
- //
- //--------------------------------------------------------------------------
- /**
- * @private
- * The number of milliseconds that must pass without any user activity
- * before SystemManager starts dispatching 'idle' events.
- */
- private static const IDLE_THRESHOLD:Number = 1000;
- /**
- * @private
- * The number of milliseconds between each 'idle' event.
- */
- private static const IDLE_INTERVAL:Number = 100;
- //--------------------------------------------------------------------------
- //
- // Class variables
- //
- //--------------------------------------------------------------------------
- /**
- * @private
- * An array of SystemManager instances loaded as child app domains
- */
- mx_internal static var allSystemManagers:Dictionary = new Dictionary(true);
- /**
- * @private
- * The last SystemManager instance loaded as child app domains
- */
- mx_internal static var lastSystemManager:SystemManager;
- //--------------------------------------------------------------------------
- //
- // Class methods
- //
- //--------------------------------------------------------------------------
- /**
- * @private
- * If a class wants to be notified when the Application instance
- * has been initialized, then it registers a callback here.
- * By using a callback mechanism, we avoid adding unwanted
- * linker dependencies on classes like HistoryManager and DragManager.
- */
- mx_internal static function registerInitCallback(initFunction:Function):void
- {
- if (!allSystemManagers || !lastSystemManager)
- {
- return;
- }
- var sm:SystemManager = lastSystemManager;
- // If this function is called late (after we're done invoking the
- // callback functions for the last time), then just invoke
- // the callback function immediately.
- if (sm.doneExecutingInitCallbacks)
- initFunction(sm);
- else
- sm.initCallbackFunctions.push(initFunction);
- }
- //--------------------------------------------------------------------------
- //
- // Constructor
- //
- //--------------------------------------------------------------------------
- /**
- * Constructor.
- *
- * <p>This is the starting point for all Flex applications.
- * This class is set to be the root class of a Flex SWF file.
- * Flash Player instantiates an instance of this class,
- * causing this constructor to be called.</p>
- */
- public function SystemManager()
- {
- super();
- // Loaded SWFs don't get a stage right away
- // and shouldn't override the main SWF's setting anyway.
- if (stage)
- {
- stage.scaleMode = StageScaleMode.NO_SCALE;
- stage.align = StageAlign.TOP_LEFT;
- }
- // If we don't have a stage then we are not top-level,
- // unless there are no other top-level managers, in which
- // case we got loaded by a non-Flex shell or are sandboxed.
- if (SystemManagerGlobals.topLevelSystemManagers.length > 0 && !stage)
- topLevel = false;
- if (!stage)
- isStageRoot = false;
- if (topLevel)
- SystemManagerGlobals.topLevelSystemManagers.push(this);
- lastSystemManager = this;
- var compiledLocales:Array = info()["compiledLocales"];
- ResourceBundle.mx_internal::locale =
- compiledLocales != null && compiledLocales.length > 0 ?
- compiledLocales[0] :
- "en_US";
- executeCallbacks();
- // Make sure to stop the playhead on the current frame.
- stop();
- // Add safeguard in case bug 129782 shows up again.
- if (topLevel && currentFrame != 1)
- {
- throw new Error("The SystemManager constructor was called when the currentFrame was at " + currentFrame +
- " Please add this SWF to bug 129782.");
- }
- // Listen for the last frame (param is 0-indexed) to be executed.
- //addFrameScript(totalFrames - 1, frameEndHandler);
- if (root && root.loaderInfo)
- root.loaderInfo.addEventListener(Event.INIT, initHandler);
-
- }
-
-
-
- /**
- * @private
- */
- private function deferredNextFrame():void
- {
- if (currentFrame + 1 > totalFrames)
- return;
- if (currentFrame + 1 <= framesLoaded)
- {
- nextFrame();
- }
- else
- {
- // Next frame isn't baked yet, so we'll check back...
- nextFrameTimer = new Timer(100);
- nextFrameTimer.addEventListener(TimerEvent.TIMER,
- nextFrameTimerHandler);
- nextFrameTimer.start();
- }
- }
- //--------------------------------------------------------------------------
- //
- // Variables
- //
- //--------------------------------------------------------------------------
- /**
- * @private
- * This flag remembers whether we're going to call executeCallbacks again
- */
- private var doneExecutingInitCallbacks:Boolean = false;
- /**
- * @private
- * This array stores pointers to all the init callback functions for this
- * system manager.
- * See registerInitCallback() for more information.
- */
- private var initCallbackFunctions:Array = [];
- /**
- * @private
- */
- private var initialized:Boolean = false;
- /**
- * @private
- * Whether we are in the top-level list or not;
- * top-level means we are the highest level SystemManager
- * for this stage.
- */
- mx_internal var topLevel:Boolean = true;
- /**
- * @private
- * Whether we are the stage root or not.
- * We are only the stage root if we were the root
- * of the first SWF that got loaded by the player.
- * Otherwise we could be top level but not stage root
- * if we are loaded by some other non-Flex shell
- * or are sandboxed.
- */
- private var isStageRoot:Boolean = true;
- /**
- * @private
- * Whether we are the first SWF loaded into a bootstrap
- * and therefore, the topLevelRoot
- */
- private var isBootstrapRoot:Boolean = false;
- /**
- * @private
- * If we're not top level, then we delegate many things
- * to the top level SystemManager.
- */
- private var _topLevelSystemManager:ISystemManager;
- /**
- * cached value of the stage.
- */
- private var _stage:Stage;
-
- /**
- * Depth of this object in the containment hierarchy.
- * This number is used by the measurement and layout code.
- */
- mx_internal var nestLevel:int = 0;
- /**
- * @private
- */
- private var rslSizes:Array = null;
- /**
- * @private
- * A reference to the preloader.
- */
- private var preloader:Preloader;
- /**
- * @private
- * The mouseCatcher is the 0th child of the SystemManager,
- * behind the application, which is child 1.
- * It is the same size as the stage and is filled with
- * transparent pixels; i.e., they've been drawn, but with alpha 0.
- *
- * Its purpose is to make every part of the stage
- * able to detect the mouse.
- * For example, a Button puts a mouseUp handler on the SystemManager
- * in order to capture mouseUp events that occur outside the Button.
- * But if the children of the SystemManager don't have "drawn-on"
- * pixels everywhere, the player won't dispatch the mouseUp.
- * We can't simply fill the SystemManager itself with
- * transparent pixels, because the player's pixel detection
- * logic doesn't look at pixels drawn into the root DisplayObject.
- *
- * Here is an example of what would happen without the mouseCatcher:
- * Run a fixed-size Application (e.g. width="600" height="600")
- * in the standalone player. Make the player window larger
- * to reveal part of the stage. Press a Button, drag off it
- * into the stage area, and release the mouse button.
- * Without the mouseCatcher, the Button wouldn't return to its "up" state.
- */
- private var mouseCatcher:Sprite;
- /**
- * @private
- * The top level window.
- */
- mx_internal var topLevelWindow:IUIComponent;
- /**
- * @private
- * List of top level windows.
- */
- private var forms:Array = [];
- /**
- * @private
- * The current top level window.
- *
- * Will be of type IFocusManagerContainer if the form
- * in the top-level system manager's application domain
- * or a child of that application domain. Otherwise the
- * form will be of type RemotePopUp.
- */
- private var form:Object;
- /**
- * @private
- * Number of frames since the last mouse or key activity.
- */
- mx_internal var idleCounter:int = 0;
- /**
- * @private
- * The Timer used to determine when to dispatch idle events.
- */
- private var idleTimer:Timer;
- /**
- * @private
- * A timer used when it is necessary to wait before incrementing the frame
- */
- private var nextFrameTimer:Timer = null;
- /**
- * @private
- * Track which frame was last processed
- */
- private var lastFrame:int;
- //--------------------------------------------------------------------------
- //
- // Overridden properties: DisplayObject
- //
- //--------------------------------------------------------------------------
- //----------------------------------
- // height
- //----------------------------------
- /**
- * @private
- */
- private var _height:Number;
- /**
- * The height of this object. For the SystemManager
- * this should always be the width of the stage unless the application was loaded
- * into another application. If the application was not loaded
- * into another application, setting this value has no effect.
- */
- override public function get height():Number
- {
- return _height;
- }
- //----------------------------------
- // stage
- //----------------------------------
- /**
- * @private
- * get the main stage if we're loaded into another swf in the same sandbox
- */
- override public function get stage():Stage
- {
- if (_stage)
- return _stage;
-
- var s:Stage = super.stage;
- if (s)
- {
- _stage = s;
- return s;
- }
- if (!topLevel && _topLevelSystemManager)
- {
- _stage = _topLevelSystemManager.stage;
- return _stage;
- }
- // Case for version skew, we are a top level system manager, but
- // a child of the top level root system manager and we have access
- // to the stage.
- if (!isStageRoot && topLevel)
- {
- var root:DisplayObject = getTopLevelRoot();
- if (root)
- {
- _stage = root.stage;
- return _stage;
- }
- }
-
- return null;
- }
- //----------------------------------
- // width
- //----------------------------------
- /**
- * @private
- */
- private var _width:Number;
- /**
- * The width of this object. For the SystemManager
- * this should always be the width of the stage unless the application was loaded
- * into another application. If the application was not loaded
- * into another application, setting this value will have no effect.
- */
- override public function get width():Number
- {
- return _width;
- }
- //--------------------------------------------------------------------------
- //
- // Overridden properties: DisplayObjectContainer
- //
- //--------------------------------------------------------------------------
- //----------------------------------
- // numChildren
- //----------------------------------
- /**
- * The number of non-floating windows. This is the main application window
- * plus any other windows added to the SystemManager that are not popups,
- * tooltips or cursors.
- */
- override public function get numChildren():int
- {
- return noTopMostIndex - applicationIndex;
- }
- //--------------------------------------------------------------------------
- //
- // Properties
- //
- //--------------------------------------------------------------------------
- //----------------------------------
- // application
- //----------------------------------
- /**
- * The application parented by this SystemManager.
- * SystemManagers create an instance of an Application
- * even if they are loaded into another Application.
- * Thus, this may not match mx.core.Application.application
- * if the SWF has been loaded into another application.
- * <p>Note that this property is not typed as mx.core.Application
- * because of load-time performance considerations
- * but can be coerced into an mx.core.Application.</p>
- */
- public function get application():IUIComponent
- {
- return IUIComponent(_document);
- }
- //----------------------------------
- // applicationIndex
- //----------------------------------
- /**
- * @private
- * Storage for the applicationIndex property.
- */
- private var _applicationIndex:int = 1;
- /**
- * @private
- * The index of the main mx.core.Application window, which is
- * effectively its z-order.
- */
- mx_internal function get applicationIndex():int
- {
- return _applicationIndex;
- }
- /**
- * @private
- */
- mx_internal function set applicationIndex(value:int):void
- {
- _applicationIndex = value;
- }
- //----------------------------------
- // bridgeToFocusManager
- //----------------------------------
-
- /**
- * @private
- * Map a bridge to a FocusManager.
- * This dictionary contains both the focus managers for this document as
- * well as focus managers that are in documents contained inside of pop
- * ups, if the system manager in that pop up requires a bridge to
- * communicate with this system manager.
- *
- * The returned object is an object of type IFocusManager.
- */
- private var _bridgeToFocusManager:Dictionary;
- /**
- * @private
- *
- * System Managers in child application domains use their parent's
- * bridgeToFocusManager's Dictionary. The swfBridgeGroup property
- * is maintained in the same way.
- */
- mx_internal function get bridgeToFocusManager():Dictionary
- {
- if (topLevel)
- return _bridgeToFocusManager;
- else if (topLevelSystemManager)
- return SystemManager(topLevelSystemManager).bridgeToFocusManager;
-
- return null;
- }
-
- mx_internal function set bridgeToFocusManager(bridgeToFMDictionary:Dictionary):void
- {
- if (topLevel)
- _bridgeToFocusManager = bridgeToFMDictionary;
- else if (topLevelSystemManager)
- SystemManager(topLevelSystemManager).bridgeToFocusManager = bridgeToFMDictionary;
-
- }
-
- //----------------------------------
- // cursorChildren
- //----------------------------------
- /**
- * @private
- * Storage for the cursorChildren property.
- */
- private var _cursorChildren:SystemChildrenList;
- /**
- * @inheritDoc
- */
- public function get cursorChildren():IChildList
- {
- if (!topLevel)
- return _topLevelSystemManager.cursorChildren;
- if (!_cursorChildren)
- {
- _cursorChildren = new SystemChildrenList(this,
- new QName(mx_internal, "toolTipIndex"),
- new QName(mx_internal, "cursorIndex"));
- }
- return _cursorChildren;
- }
- //----------------------------------
- // cursorIndex
- //----------------------------------
- /**
- * @private
- * Storage for the toolTipIndex property.
- */
- private var _cursorIndex:int = 0;
- /**
- * @private
- * The index of the highest child that is a cursor.
- */
- mx_internal function get cursorIndex():int
- {
- return _cursorIndex;
- }
- /**
- * @private
- */
- mx_internal function set cursorIndex(value:int):void
- {
- var delta:int = value - _cursorIndex;
- _cursorIndex = value;
- }
- //----------------------------------
- // document
- //----------------------------------
- /**
- * @private
- * Storage for the document property.
- */
- private var _document:Object;
- /**
- * @inheritDoc
- */
- public function get document():Object
- {
- return _document;
- }
- /**
- * @private
- */
- public function set document(value:Object):void
- {
- _document = value;
- }
- //----------------------------------
- // embeddedFontList
- //----------------------------------
- /**
- * @private
- * Storage for the fontList property.
- */
- private var _fontList:Object = null;
- /**
- * A table of embedded fonts in this application. The
- * object is a table indexed by the font name.
- */
- public function get embeddedFontList():Object
- {
- if (_fontList == null)
- {
- _fontList = {};
- var o:Object = info()["fonts"];
- var p:String;
- for (p in o)
- {
- _fontList[p] = o[p];
- }
- // FIXME: font rules across SWF boundaries have not been finalized!
- // Top level systemManager may not be defined if SWF is loaded
- // as a background image in download progress bar.
- if (!topLevel && _topLevelSystemManager)
- {
- var fl:Object = _topLevelSystemManager.embeddedFontList;
- for (p in fl)
- {
- _fontList[p] = fl[p];
- }
- }
- }
- return _fontList;
- }
- //----------------------------------
- // explicitHeight
- //----------------------------------
- /**
- * @private
- */
- private var _explicitHeight:Number;
- /**
- * The explicit width of this object. For the SystemManager
- * this should always be NaN unless the application was loaded
- * into another application. If the application was not loaded
- * into another application, setting this value has no effect.
- */
- public function get explicitHeight():Number
- {
- return _explicitHeight;
- }
- /**
- * @private
- */
- public function set explicitHeight(value:Number):void
- {
- _explicitHeight = value;
- }
- //----------------------------------
- // explicitWidth
- //----------------------------------
- /**
- * @private
- */
- private var _explicitWidth:Number;
- /**
- * The explicit width of this object. For the SystemManager
- * this should always be NaN unless the application was loaded
- * into another application. If the application was not loaded
- * into another application, setting this value has no effect.
- */
- public function get explicitWidth():Number
- {
- return _explicitWidth;
- }
- /**
- * @private
- */
- public function set explicitWidth(value:Number):void
- {
- _explicitWidth = value;
- }
- //----------------------------------
- // focusPane
- //----------------------------------
- /**
- * @private
- */
- private var _focusPane:Sprite;
- /**
- * @copy mx.core.UIComponent#focusPane
- */
- public function get focusPane():Sprite
- {
- return _focusPane;
- }
- /**
- * @private
- */
- public function set focusPane(value:Sprite):void
- {
- if (value)
- {
- addChild(value);
- value.x = 0;
- value.y = 0;
- value.scrollRect = null;
- _focusPane = value;
- }
- else
- {
- removeChild(_focusPane);
- _focusPane = null;
- }
- }
- //----------------------------------
- // info
- //----------------------------------
- /**
- * @private
- */
- public function info():Object
- {
- return {};
- }
- //----------------------------------
- // measuredHeight
- //----------------------------------
- /**
- * The measuredHeight is the explicit or measuredHeight of
- * the main mx.core.Application window
- * or the starting height of the SWF if the main window
- * has not yet been created or does not exist.
- */
- public function get measuredHeight():Number
- {
- return topLevelWindow ?
- topLevelWindow.getExplicitOrMeasuredHeight() :
- loaderInfo.height;
- }
- //----------------------------------
- // measuredWidth
- //----------------------------------
- /**
- * The measuredWidth is the explicit or measuredWidth of
- * the main mx.core.Application window,
- * or the starting width of the SWF if the main window
- * has not yet been created or does not exist.
- */
- public function get measuredWidth():Number
- {
- return topLevelWindow ?
- topLevelWindow.getExplicitOrMeasuredWidth() :
- loaderInfo.width;
- }
- //----------------------------------
- // noTopMostIndex
- //----------------------------------
- /**
- * @private
- * Storage for the noTopMostIndex property.
- */
- private var _noTopMostIndex:int = 0;
- /**
- * @private
- * The index of the highest child that isn't a topmost/popup window
- */
- mx_internal function get noTopMostIndex():int
- {
- return _noTopMostIndex;
- }
- /**
- * @private
- */
- mx_internal function set noTopMostIndex(value:int):void
- {
- var delta:int = value - _noTopMostIndex;
- _noTopMostIndex = value;
- topMostIndex += delta;
- }
- //----------------------------------
- // $numChildren
- //----------------------------------
- /**
- * @private
- * This property allows access to the Player's native implementation
- * of the numChildren property, which can be useful since components
- * can override numChildren and thereby hide the native implementation.
- * Note that this "base property" is final and cannot be overridden,
- * so you can count on it to reflect what is happening at the player level.
- */
- mx_internal final function get $numChildren():int
- {
- return super.numChildren;
- }
- //----------------------------------
- // numModalWindows
- //----------------------------------
- /**
- * @private
- * Storage for the numModalWindows property.
- */
- private var _numModalWindows:int = 0;
- /**
- * The number of modal windows. Modal windows don't allow
- * clicking in another windows which would normally
- * activate the FocusManager in that window. The PopUpManager
- * modifies this count as it creates and destroys modal windows.
- */
- public function get numModalWindows():int
- {
- return _numModalWindows;
- }
- /**
- * @private
- */
- public function set numModalWindows(value:int):void
- {
- _numModalWindows = value;
- }
- //----------------------------------
- // preloaderBackgroundAlpha
- //----------------------------------
- /**
- * The background alpha used by the child of the preloader.
- */
- public function get preloaderBackgroundAlpha():Number
- {
- return info()["backgroundAlpha"];
- }
- //----------------------------------
- // preloaderBackgroundColor
- //----------------------------------
- /**
- * The background color used by the child of the preloader.
- */
- public function get preloaderBackgroundColor():uint
- {
- var value:* = info()["backgroundColor"];
- if (value == undefined)
- return StyleManager.NOT_A_COLOR;
- else
- return StyleManager.getColorName(value);
- }
- //----------------------------------
- // preloaderBackgroundImage
- //----------------------------------
- /**
- * The background color used by the child of the preloader.
- */
- public function get preloaderBackgroundImage():Object
- {
- return info()["backgroundImage"];
- }
- //----------------------------------
- // preloaderBackgroundSize
- //----------------------------------
- /**
- * The background size used by the child of the preloader.
- */
- public function get preloaderBackgroundSize():String
- {
- return info()["backgroundSize"];
- }
- //----------------------------------
- // popUpChildren
- //----------------------------------
- /**
- * @private
- * Storage for the popUpChildren property.
- */
- private var _popUpChildren:SystemChildrenList;
- /**
- * @inheritDoc
- */
- public function get popUpChildren():IChildList
- {
- if (!topLevel)
- return _topLevelSystemManager.popUpChildren;
- if (!_popUpChildren)
- {
- _popUpChildren = new SystemChildrenList(this,
- new QName(mx_internal, "noTopMostIndex"),
- new QName(mx_internal, "topMostIndex"));
- }
- return _popUpChildren;
- }
- //----------------------------------
- // rawChildren
- //----------------------------------
- /**
- * @private
- * Storage for the rawChildren property.
- */
- private var _rawChildren:SystemRawChildrenList;
- /**
- * @inheritDoc
- */
- public function get rawChildren():IChildList
- {
- //if (!topLevel)
- // return _topLevelSystemManager.rawChildren;
- if (!_rawChildren)
- _rawChildren = new SystemRawChildrenList(this);
- return _rawChildren;
- }
- //--------------------------------------------------------------------------
- // sandbox bridge group
- //--------------------------------------------------------------------------
-
- /**
- * @private
- *
- * Represents the related parent and child sandboxs this SystemManager may
- * communicate with.
- */
- private var _swfBridgeGroup:ISWFBridgeGroup;
-
-
- public function get swfBridgeGroup():ISWFBridgeGroup
- {
- if (topLevel)
- return _swfBridgeGroup;
- else if (topLevelSystemManager)
- return topLevelSystemManager.swfBridgeGroup;
-
- return null;
- }
-
- public function set swfBridgeGroup(bridgeGroup:ISWFBridgeGroup):void
- {
- if (topLevel)
- _swfBridgeGroup = bridgeGroup;
- else if (topLevelSystemManager)
- SystemManager(topLevelSystemManager).swfBridgeGroup = bridgeGroup;
-
- }
-
- //--------------------------------------------------------------------------
- // screen
- //--------------------------------------------------------------------------
- /**
- * @private
- * Storage for the screen property.
- */
- private var _screen:Rectangle;
- /**
- * @inheritDoc
- */
- public function get screen():Rectangle
- {
- if (!_screen)
- Stage_resizeHandler();
- if (!isStageRoot)
- {
- Stage_resizeHandler();
- }
- return _screen;
- }
- //----------------------------------
- // toolTipChildren
- //----------------------------------
- /**
- * @private
- * Storage for the toolTipChildren property.
- */
- private var _toolTipChildren:SystemChildrenList;
- /**
- * @inheritDoc
- */
- public function get toolTipChildren():IChildList
- {
- if (!topLevel)
- return _topLevelSystemManager.toolTipChildren;
- if (!_toolTipChildren)
- {
- _toolTipChildren = new SystemChildrenList(this,
- new QName(mx_internal, "topMostIndex"),
- new QName(mx_internal, "toolTipIndex"));
- }
- return _toolTipChildren;
- }
- //----------------------------------
- // toolTipIndex
- //----------------------------------
- /**
- * @private
- * Storage for the toolTipIndex property.
- */
- private var _toolTipIndex:int = 0;
- /**
- * @private
- * The index of the highest child that is a tooltip
- */
- mx_internal function get toolTipIndex():int
- {
- return _toolTipIndex;
- }
- /**
- * @private
- */
- mx_internal function set toolTipIndex(value:int):void
- {
- var delta:int = value - _toolTipIndex;
- _toolTipIndex = value;
- cursorIndex += delta;
- }
- //----------------------------------
- // topLevelSystemManager
- //----------------------------------
- /**
- * Returns the SystemManager responsible for the application window. This will be
- * the same SystemManager unless this application has been loaded into another
- * application.
- */
- public function get topLevelSystemManager():ISystemManager
- {
- if (topLevel)
- return this;
- return _topLevelSystemManager;
- }
- //----------------------------------
- // topMostIndex
- //----------------------------------
- /**
- * @private
- * Storage for the topMostIndex property.
- */
- private var _topMostIndex:int = 0;
- /**
- * @private
- * The index of the highest child that is a topmost/popup window
- */
- mx_internal function get topMostIndex():int
- {
- return _topMostIndex;
- }
- mx_internal function set topMostIndex(value:int):void
- {
- var delta:int = value - _topMostIndex;
- _topMostIndex = value;
- toolTipIndex += delta;
- }
- //--------------------------------------------------------------------------
- //
- // Properties: ISWFBridgeProvider
- //
- //--------------------------------------------------------------------------
- /**
- * @inheritDoc
- */
- public function get swfBridge():IEventDispatcher
- {
- if (swfBridgeGroup)
- return swfBridgeGroup.parentBridge;
-
- return null;
- }
-
- /**
- * @inheritDoc
- */
- public function get childAllowsParent():Boolean
- {
- try
- {
- return loaderInfo.childAllowsParent;
- }
- catch (error:Error)
- {
- //Error #2099: The loading object is not sufficiently loaded to provide this information.
- }
-
- return false; // assume the worst
- }
- /**
- * @inheritDoc
- */
- public function get parentAllowsChild():Boolean
- {
- try
- {
- return loaderInfo.parentAllowsChild;
- }
- catch (error:Error)
- {
- //Error #2099: The loading object is not sufficiently loaded to provide this information.
- }
-
- return false; // assume the worst
- }
- /**
- * @private
- *
- * true if redipatching a resize event.
- */
- private var isDispatchingResizeEvent:Boolean;
-
- /**
- * @private
- *
- * Used to locate untrusted forms. Maps string ids to Objects.
- * The object make be the SystemManagerProxy of a form or it may be
- * the bridge to the child application where the object lives.
- */
- private var idToPlaceholder:Object;
-
- private var eventProxy:EventProxy;
- private var weakReferenceProxies:Dictionary = new Dictionary(true);
- private var strongReferenceProxies:Dictionary = new Dictionary(false);
- //--------------------------------------------------------------------------
- //
- // Overridden methods: EventDispatcher
- //
- //--------------------------------------------------------------------------
- /**
- * @private
- * Only create idle events if someone is listening.
- */
- override public function addEventListener(type:String, listener:Function,
- useCapture:Boolean = false,
- priority:int = 0,
- useWeakReference:Boolean = false):void
- {
- // These two events will dispatched to applications in sandboxes.
- if (type == FlexEvent.RENDER || type == FlexEvent.ENTER_FRAME)
- {
- if (type == FlexEvent.RENDER)
- type = Event.RENDER;
- else
- type = Event.ENTER_FRAME;
-
- try
- {
- if (stage)
- stage.addEventListener(type, listener, useCapture, priority, useWeakReference);
- else
- super.addEventListener(type, listener, useCapture, priority, useWeakReference);
- }
- catch (error:SecurityError)
- {
- super.addEventListener(type, listener, useCapture, priority, useWeakReference);
- }
-
- if (stage && type == Event.RENDER)
- stage.invalidate();
- return;
- }
- if (type == MouseEvent.MOUSE_MOVE || type == MouseEvent.MOUSE_UP || type == MouseEvent.MOUSE_DOWN
- || type == Event.ACTIVATE || type == Event.DEACTIVATE)
- {
- // also listen to stage if allowed
- try
- {
- if (stage)
- {
- var newListener:StageEventProxy = new StageEventProxy(listener);
- stage.addEventListener(type, newListener.stageListener, false, priority, useWeakReference);
- if (useWeakReference)
- weakReferenceProxies[listener] = newListener;
- else
- strongReferenceProxies[listener] = newListener;
- }
- }
- catch (error:SecurityError)
- {
- }
- }
- if (hasSWFBridges() || SystemManagerGlobals.topLevelSystemManagers.length > 1)
- {
- if (!eventProxy)
- {
- eventProxy = new EventProxy(this);
- }
- var actualType:String = EventUtil.sandboxMouseEventMap[type];
- if (actualType)
- {
- if (isTopLevelRoot())
- {
- stage.addEventListener(MouseEvent.MOUSE_MOVE, resetMouseCursorTracking, true, EventPriority.CURSOR_MANAGEMENT + 1, true);
- addEventListenerToSandboxes(SandboxMouseEvent.MOUSE_MOVE_SOMEWHERE, resetMouseCursorTracking, true, EventPriority.CURSOR_MANAGEMENT + 1, true);
- }
- else
- {
- super.addEventListener(MouseEvent.MOUSE_MOVE, resetMouseCursorTracking, true, EventPriority.CURSOR_MANAGEMENT + 1, true);
- }
-
- addEventListenerToSandboxes(type, sandboxMouseListener, useCapture, priority, useWeakReference);
- if (!SystemManagerGlobals.changingListenersInOtherSystemManagers)
- addEventListenerToOtherSystemManagers(type, otherSystemManagerMouseListener, useCapture, priority, useWeakReference)
- if (getSandboxRoot() == this)
- super.addEventListener(actualType, eventProxy.marshalListener,
- useCapture, priority, useWeakReference);
-
- // Set useCapture to false because we will never see an event
- // marshalled in the capture phase.
- super.addEventListener(type, listener, false, priority, useWeakReference);
- return;
- }
- }
-
- // When the first listener registers for 'idle' events,
- // create a Timer that will fire every IDLE_INTERVAL.
- if (type == FlexEvent.IDLE && !idleTimer)
- {
- idleTimer = new Timer(IDLE_INTERVAL);
- idleTimer.addEventListener(TimerEvent.TIMER,
- idleTimer_timerHandler);
- idleTimer.start();
- // Make sure we get all activity
- // in case someone calls stopPropagation().
- addEventListener(MouseEvent.MOUSE_MOVE, mouseMoveHandler, true);
- addEventListener(MouseEvent.MOUSE_UP, mouseUpHandler, true);
- }
- super.addEventListener(type, listener, useCapture, priority, useWeakReference);
- }
-
- /**
- * @private
- *
- * Test if this system manager has any sandbox bridges.
- *
- * @return true if there are sandbox bridges, false otherwise.
- */
- private function hasSWFBridges():Boolean
- {
- if (swfBridgeGroup)
- return true;
-
- return false;
- }
-
- /**
- * @private
- */
- override public function removeEventListener(type:String, listener:Function,
- useCapture:Boolean = false):void
- {
- // These two events will dispatched to applications in sandboxes.
- if (type == FlexEvent.RENDER || type == FlexEvent.ENTER_FRAME)
- {
- if (type == FlexEvent.RENDER)
- type = Event.RENDER;
- else
- type = Event.ENTER_FRAME;
-
- try
- {
- // Remove both listeners in case the system manager was added
- // or removed from the stage after the listener was added.
- if (stage)
- stage.removeEventListener(type, listener, useCapture);
- super.removeEventListener(type, listener, useCapture);
- }
- catch (error:SecurityError)
- {
- super.removeEventListener(type, listener, useCapture);
- }
-
- return;
- }
- if (type == MouseEvent.MOUSE_MOVE || type == MouseEvent.MOUSE_UP || type == MouseEvent.MOUSE_DOWN
- || type == Event.ACTIVATE || type == Event.DEACTIVATE)
- {
- // also listen to stage if allowed
- try
- {
- if (stage)
- {
- var newListener:StageEventProxy = weakReferenceProxies[listener];
- if (!newListener)
- {
- newListener = strongReferenceProxies[listener];
- if (newListener)
- delete strongReferenceProxies[listener];
- }
- if (newListener)
- stage.removeEventListener(type, newListener.stageListener, false);
- }
- }
- catch (error:SecurityError)
- {
- }
- }
-
- if (hasSWFBridges() || SystemManagerGlobals.topLevelSystemManagers.length > 1)
- {
- var actualType:String = EventUtil.sandboxMouseEventMap[type];
- if (actualType)
- {
- if (getSandboxRoot() == this && eventProxy)
- super.removeEventListener(actualType, eventProxy.marshalListener,
- useCapture);
- if (!SystemManagerGlobals.changingListenersInOtherSystemManagers)
- removeEventListenerFromOtherSystemManagers(type, otherSystemManagerMouseListener, useCapture);
- removeEventListenerFromSandboxes(type, sandboxMouseListener, useCapture);
- super.removeEventListener(type, listener, false);
- return;
- }
- }
-
- // When the last listener unregisters for 'idle' events,
- // stop and release the Timer.
- if (type == FlexEvent.IDLE)
- {
- super.removeEventListener(type, listener, useCapture);
- if (!hasEventListener(FlexEvent.IDLE) && idleTimer)
- {
- idleTimer.stop();
- idleTimer = null;
- removeEventListener(MouseEvent.MOUSE_MOVE, mouseMoveHandler);
- removeEventListener(MouseEvent.MOUSE_UP, mouseUpHandler);
- }
- }
- else
- {
- super.removeEventListener(type, listener, useCapture);
- }
- }
- //--------------------------------------------------------------------------
- //
- // Overridden methods: DisplayObjectContainer
- //
- //--------------------------------------------------------------------------
- /**
- * @private
- */
- override public function addChild(child:DisplayObject):DisplayObject
- {
- // Adjust the partition indexes
- // before the "added" event is dispatched.
- noTopMostIndex++;
- return rawChildren_addChildAt(child, noTopMostIndex - 1);
- }
- /**
- * @private
- */
- override public function addChildAt(child:DisplayObject,
- index:int):DisplayObject
- {
- // Adjust the partition indexes
- // before the "added" event is dispatched.
- noTopMostIndex++;
- return rawChildren_addChildAt(child, applicationIndex + index);
- }
-
- /**
- * @private
- *
- * Used by SystemManagerProxy to add a mouse catcher as a child.
- */
- mx_internal final function $addChildAt(child:DisplayObject,
- index:int):DisplayObject
- {
- return super.addChildAt(child, index);
- }
- /**
- * @private
- *
- * Companion to $addChildAt.
- */
- mx_internal final function $removeChildAt(index:int):DisplayObject
- {
- return super.removeChildAt(index);
- }
- /**
- * @private
- */
- override public function removeChild(child:DisplayObject):DisplayObject
- {
- // Adjust the partition indexes
- // before the "removed" event is dispatched.
- noTopMostIndex--;
- return rawChildren_removeChild(child);
- }
- /**
- * @private
- */
- override public function removeChildAt(index:int):DisplayObject
- {
- // Adjust the partition indexes
- // before the "removed" event is dispatched.
- noTopMostIndex--;
- return rawChildren_removeChildAt(applicationIndex + index);
- }
- /**
- * @private
- */
- override public function getChildAt(index:int):DisplayObject
- {
- return super.getChildAt(applicationIndex + index)
- }
- /**
- * @private
- */
- override public function getChildByName(name:String):DisplayObject
- {
- return super.getChildByName(name);
- }
- /**
- * @private
- */
- override public function getChildIndex(child:DisplayObject):int
- {
- return super.getChildIndex(child) - applicationIndex;
- }
- /**
- * @private
- */
- override public function setChildIndex(child:DisplayObject, newIndex:int):void
- {
- super.setChildIndex(child, applicationIndex + newIndex)
- }
- /**
- * @private
- */
- override public function getObjectsUnderPoint(point:Point):Array
- {
- var children:Array = [];
- // Get all the children that aren't tooltips and cursors.
- var n:int = topMostIndex;
- for (var i:int = 0; i < n; i++)
- {
- var child:DisplayObject = super.getChildAt(i);
- if (child is DisplayObjectContainer)
- {
- var temp:Array =
- DisplayObjectContainer(child).getObjectsUnderPoint(point);
- if (temp)
- children = children.concat(temp);
- }
- }
- return children;
- }
- /**
- * @private
- */
- override public function contains(child:DisplayObject):Boolean
- {
- if (super.contains(child))
- {
- if (child.parent == this)
- {
- var childIndex:int = super.getChildIndex(child);
- if (childIndex < noTopMostIndex)
- return true;
- }
- else
- {
- for (var i:int = 0; i < noTopMostIndex; i++)
- {
- var myChild:DisplayObject = super.getChildAt(i);
- if (myChild is IRawChildrenContainer)
- {
- if (IRawChildrenContainer(myChild).rawChildren.contains(child))
- return true;
- }
- if (myChild is DisplayObjectContainer)
- {
- if (DisplayObjectContainer(myChild).contains(child))
- return true;
- }
- }
- }
- }
- return false;
- }
- //--------------------------------------------------------------------------
- //
- // Methods: Initialization
- //
- //--------------------------------------------------------------------------
- /**
- * A factory method that requests an instance of a
- * definition known to the module.
- *
- * You can provide an optional set of parameters to let building
- * factories change what they create based on the
- * input. Passing null indicates that the default definition
- * is created, if possible.
- *
- * This method is overridden in the autogenerated subclass.
- *
- * @param params An optional list of arguments. You can pass
- * any number of arguments, which are then stored in an Array
- * called <code>parameters</code>.
- *
- * @return An instance of the module, or <code>null</code>.
- */
- public function create(... params):Object
- {
- var mainClassName:String = info()["mainClassName"];
- if (mainClassName == null)
- {
- var url:String = loaderInfo.loaderURL;
- var dot:int = url.lastIndexOf(".");
- var slash:int = url.lastIndexOf("/");
- mainClassName = url.substring(slash + 1, dot);
- }
- var mainClass:Class = Class(getDefinitionByName(mainClassName));
-
- return mainClass ? new mainClass() : null;
- }
- /**
- * @private
- * Creates an instance of the preloader, adds it as a child, and runs it.
- * This is needed by FlexBuilder. Do not modify this function.
- */
- mx_internal function initialize():void
- {
- if (isStageRoot)
- {
- _width = stage.stageWidth;
- _height = stage.stageHeight;
- }
- else
- {
- _width = loaderInfo.width;
- _height = loaderInfo.height;
- }
- // Create an instance of the preloader and add it to the stage
- preloader = new Preloader();
- // Listen for preloader events
- // Once the preloader dispatches initStart, then create the application instance
- preloader.addEventListener(FlexEvent.INIT_PROGRESS,
- preloader_initProgressHandler);
- preloader.addEventListener(FlexEvent.PRELOADER_DONE,
- preloader_preloaderDoneHandler);
- // Add the preloader as a child. Use backing variable because when loaded
- // we redirect public API to parent systemmanager
- if (!_popUpChildren)
- {
- _popUpChildren = new SystemChildrenList(
- this, new QName(mx_internal, "noTopMostIndex"), new QName(mx_internal, "topMostIndex"));
- }
- _popUpChildren.addChild(preloader);
- var rsls:Array = info()["rsls"];
- var cdRsls:Array = info()["cdRsls"];
- var usePreloader:Boolean = true;
- if (info()["usePreloader"] != undefined)
- usePreloader = info()["usePreloader"];
- var preloaderDisplayClass:Class = info()["preloader"] as Class;
- if (usePreloader && !preloaderDisplayClass)
- preloaderDisplayClass = DownloadProgressBar;
- // Put cross-domain RSL information in the RSL list.
- var rslList:Array = [];
- var n:int;
- var i:int;
- if (cdRsls && cdRsls.length > 0)
- {
- var crossDomainRSLItem:Class = Class(getDefinitionByName("mx.core::CrossDomainRSLItem"));
- n = cdRsls.length;
- for (i = 0; i < n; i++)
- {
- // If crossDomainRSLItem is null, then this is a compiler error. It should not be null.
- var cdNode:Object = new crossDomainRSLItem(cdRsls[i]["rsls"],
- cdRsls[i]["policyFiles"],
- cdRsls[i]["digests"],
- cdRsls[i]["types"],
- cdRsls[i]["isSigned"],
- LoaderUtil.normalizeURL(this.loaderInfo));
- rslList.push(cdNode);
- }
- }
- // Append RSL information in the RSL list.
- if (rsls != null && rsls.length > 0)
- {
- n = rsls.length;
- for (i = 0; i < n; i++)
- {
- var node:RSLItem = new RSLItem(rsls[i].url, LoaderUtil.normalizeURL(this.loaderInfo));
- rslList.push(node);
- }
- }
- // Register the ResourceManager class with Singleton early
- // so that we can use the ResourceManager in frame 1.
- // Same with EmbfeddedFontRegistry and StyleManager
- // The other managers get registered with Singleton later,
- // in frame 2, by docFrameHandler().
- Singleton.registerClass("mx.resources::IResourceManager",
- Class(getDefinitionByName("mx.resources::ResourceManagerImpl")));
- var resourceManager:IResourceManager = ResourceManager.getInstance();
- var fontRegistry:EmbeddedFontRegistry; // link in the EmbeddedFontRegistry Class…