          bridge.dispatchEvent(request);
     }
     
-	/**
-	 *  @private
-	 *  Makes the mouseCatcher the same size as the stage,
-	 *  filling it with transparent pixels.
-	 */
-	private function resizeMouseCatcher():void
-	{
-		if (mouseCatcher)
-		{
-			try
-			{
-			var g:Graphics = mouseCatcher.graphics;
-			var s:Rectangle = screen;
-			g.clear();
-			g.beginFill(0x000000, 0);
-			g.drawRect(0, 0, s.width, s.height);
-			g.endFill();
-			}
-			catch (e:SecurityError)
-			{
-				// trace("resizeMouseCatcher: ignoring security error " + e);
-			}
-		}
-	}
-
-	//--------------------------------------------------------------------------
-	//
-	//  Event handlers
-	//
-	//--------------------------------------------------------------------------
-
-	/**
-	 *  @private
-	 */
-	private function initHandler(event:Event):void
-	{
-		// we can still be the top level root if we can access our
-		// parent and get a positive response to the query or
-		// or there is not a listener for the new application event
-		// that SWFLoader always adds. 
-		if (!isStageRoot)
-		{
-			if (root.loaderInfo.parentAllowsChild)
-			{
-				try
-				{
+    /**
+     *  @private
+     *  Makes the mouseCatcher the same size as the stage,
+     *  filling it with transparent pixels.
+     */
+    private function resizeMouseCatcher():void
+    {
+        if (mouseCatcher)
+        {
+            try
+            {
+            var g:Graphics = mouseCatcher.graphics;
+            var s:Rectangle = screen;
+            g.clear();
+            g.beginFill(0x000000, 0);
+            g.drawRect(0, 0, s.width, s.height);
+            g.endFill();
+            }
+            catch (e:SecurityError)
+            {
+                // trace("resizeMouseCatcher: ignoring security error " + e);
+            }
+        }
+    }
+
+    //--------------------------------------------------------------------------
+    //
+    //  Event handlers
+    //
+    //--------------------------------------------------------------------------
+
+    /**
+     *  @private
+     */
+    private function initHandler(event:Event):void
+    {
+        // we can still be the top level root if we can access our
+        // parent and get a positive response to the query or
+        // or there is not a listener for the new application event
+        // that SWFLoader always adds. 
+        if (!isStageRoot)
+        {
+            if (root.loaderInfo.parentAllowsChild)
+            {
+                try
+                {
                     if (!parent.dispatchEvent(new Event("mx.managers.SystemManager.isBootstrapRoot", false, true)) ||
                         !root.loaderInfo.sharedEvents.hasEventListener(SWFBridgeEvent.BRIDGE_NEW_APPLICATION))
-						isBootstrapRoot = true;
-				}
-				catch (e:Error)
-				{
-				}
-			}
-		}
-
-		allSystemManagers[this] = this.loaderInfo.url;
-	    root.loaderInfo.removeEventListener(Event.INIT, initHandler);
-
-		if (useSWFBridge())
-		{
-			// create a bridge so we can talk to our parent.
-			swfBridgeGroup = new SWFBridgeGroup(this);
-			swfBridgeGroup.parentBridge = loaderInfo.sharedEvents;
-			addParentBridgeListeners();
-
-			// send message to parent that we are ready.
-			// pass up the sandbox bridge to the parent so its knows who we are.
-			var bridgeEvent:SWFBridgeEvent = new SWFBridgeEvent(SWFBridgeEvent.BRIDGE_NEW_APPLICATION);
-			bridgeEvent.data = swfBridgeGroup.parentBridge;
-			
-			swfBridgeGroup.parentBridge.dispatchEvent(bridgeEvent);
-
-			// placeholder popups are started locally
-			addEventListener(SWFBridgeRequest.ADD_POP_UP_PLACE_HOLDER_REQUEST, addPlaceholderPopupRequestHandler);
-
-			root.loaderInfo.addEventListener(Event.UNLOAD, unloadHandler, false, 0, true);
-		}
-
-		// every SM has to have this listener in case it is the SM for some child AD that contains a manager
-		// and the parent ADs don't have that manager.
-		var sbRoot:DisplayObject = getSandboxRoot();
-		sbRoot.addEventListener(InterManagerRequest.INIT_MANAGER_REQUEST, initManagerHandler, false, 0, true);
-
-		// once managers get initialized, they bounce things off the sandbox root
-		if (sbRoot == this)
-		{
-			addEventListener(InterManagerRequest.SYSTEM_MANAGER_REQUEST, systemManagerHandler);
-			addEventListener(InterManagerRequest.DRAG_MANAGER_REQUEST, multiWindowRedispatcher);
-			// listened for w/o use of constants because of dependency issues
-			//addEventListener(InterDragManagerEvent.DISPATCH_DRAG_EVENT, multiWindowRedispatcher);
-			addEventListener("dispatchDragEvent", multiWindowRedispatcher);
+                        isBootstrapRoot = true;
+                }
+                catch (e:Error)
+                {
+                }
+            }
+        }
+
+        allSystemManagers[this] = this.loaderInfo.url;
+        root.loaderInfo.removeEventListener(Event.INIT, initHandler);
+
+        if (useSWFBridge())
+        {
+            // create a bridge so we can talk to our parent.
+            swfBridgeGroup = new SWFBridgeGroup(this);
+            swfBridgeGroup.parentBridge = loaderInfo.sharedEvents;
+            addParentBridgeListeners();
+
+            // send message to parent that we are ready.
+            // pass up the sandbox bridge to the parent so its knows who we are.
+            var bridgeEvent:SWFBridgeEvent = new SWFBridgeEvent(SWFBridgeEvent.BRIDGE_NEW_APPLICATION);
+            bridgeEvent.data = swfBridgeGroup.parentBridge;
+            
+            swfBridgeGroup.parentBridge.dispatchEvent(bridgeEvent);
+
+            // placeholder popups are started locally
+            addEventListener(SWFBridgeRequest.ADD_POP_UP_PLACE_HOLDER_REQUEST, addPlaceholderPopupRequestHandler);
+
+            root.loaderInfo.addEventListener(Event.UNLOAD, unloadHandler, false, 0, true);
+        }
+
+        // every SM has to have this listener in case it is the SM for some child AD that contains a manager
+        // and the parent ADs don't have that manager.
+        var sbRoot:DisplayObject = getSandboxRoot();
+        sbRoot.addEventListener(InterManagerRequest.INIT_MANAGER_REQUEST, initManagerHandler, false, 0, true);
+
+        // once managers get initialized, they bounce things off the sandbox root
+        if (sbRoot == this)
+        {
+            addEventListener(InterManagerRequest.SYSTEM_MANAGER_REQUEST, systemManagerHandler);
+            addEventListener(InterManagerRequest.DRAG_MANAGER_REQUEST, multiWindowRedispatcher);
+            // listened for w/o use of constants because of dependency issues
+            //addEventListener(InterDragManagerEvent.DISPATCH_DRAG_EVENT, multiWindowRedispatcher);
+            addEventListener("dispatchDragEvent", multiWindowRedispatcher);
 
             addEventListener(SWFBridgeRequest.ADD_POP_UP_REQUEST, addPopupRequestHandler);
             addEventListener(SWFBridgeRequest.REMOVE_POP_UP_REQUEST, removePopupRequestHandler);
-			addEventListener(SWFBridgeRequest.ADD_POP_UP_PLACE_HOLDER_REQUEST, addPlaceholderPopupRequestHandler);
-			addEventListener(SWFBridgeRequest.REMOVE_POP_UP_PLACE_HOLDER_REQUEST, removePlaceholderPopupRequestHandler);
-			addEventListener(SWFBridgeEvent.BRIDGE_WINDOW_ACTIVATE, activateFormSandboxEventHandler);
-			addEventListener(SWFBridgeEvent.BRIDGE_WINDOW_DEACTIVATE, deactivateFormSandboxEventHandler); 
-			addEventListener(SWFBridgeRequest.HIDE_MOUSE_CURSOR_REQUEST, hideMouseCursorRequestHandler);
-			addEventListener(SWFBridgeRequest.SHOW_MOUSE_CURSOR_REQUEST, showMouseCursorRequestHandler);
-			addEventListener(SWFBridgeRequest.RESET_MOUSE_CURSOR_REQUEST, resetMouseCursorRequestHandler);
-		}
-
-	    var docFrame:int = (totalFrames == 1)? 0 : 1;
-		addEventListener(Event.ENTER_FRAME, docFrameListener);
-
-		/*
+            addEventListener(SWFBridgeRequest.ADD_POP_UP_PLACE_HOLDER_REQUEST, addPlaceholderPopupRequestHandler);
+            addEventListener(SWFBridgeRequest.REMOVE_POP_UP_PLACE_HOLDER_REQUEST, removePlaceholderPopupRequestHandler);
+            addEventListener(SWFBridgeEvent.BRIDGE_WINDOW_ACTIVATE, activateFormSandboxEventHandler);
+            addEventListener(SWFBridgeEvent.BRIDGE_WINDOW_DEACTIVATE, deactivateFormSandboxEventHandler); 
+            addEventListener(SWFBridgeRequest.HIDE_MOUSE_CURSOR_REQUEST, hideMouseCursorRequestHandler);
+            addEventListener(SWFBridgeRequest.SHOW_MOUSE_CURSOR_REQUEST, showMouseCursorRequestHandler);
+            addEventListener(SWFBridgeRequest.RESET_MOUSE_CURSOR_REQUEST, resetMouseCursorRequestHandler);
+        }
+
+        var docFrame:int = (totalFrames == 1)? 0 : 1;
+        addEventListener(Event.ENTER_FRAME, docFrameListener);
+
+        /*
         addFrameScript(docFrame, docFrameHandler);
-	    for (var f:int = docFrame + 1; f < totalFrames; ++f)
-	    {
-		    addFrameScript(f, extraFrameHandler);
-		}
-		*  
-		*  @langversion 3.0
-		*  @playerversion Flash 9
-		*  @playerversion AIR 1.1
-		*  @productversion Flex 3
-		*/
-
-	    initialize();
-	    
-	}
-
-	private function docFrameListener(event:Event):void
-	{
-		if (currentFrame == 2)
-		{
-			removeEventListener(Event.ENTER_FRAME, docFrameListener);
-			if (totalFrames > 2)
-				addEventListener(Event.ENTER_FRAME, extraFrameListener);
-
-			docFrameHandler();
-		}
-	}
-
-	private function extraFrameListener(event:Event):void
-	{
-		if (lastFrame == currentFrame)
-			return;
-
-		lastFrame = currentFrame;
-
-		if (currentFrame + 1 > totalFrames)
-			removeEventListener(Event.ENTER_FRAME, extraFrameListener);
-
-		extraFrameHandler();
-	}
-
-	/**
-	 *  @private
-	 *  Once the swf has been fully downloaded,
-	 *  advance the playhead to the next frame.
-	 *  This will cause the framescript to run, which runs frameEndHandler().
-	 */
-	private function preloader_initProgressHandler(event:Event):void
-	{
-		// Advance the next frame
-		preloader.removeEventListener(FlexEvent.INIT_PROGRESS,
-									  preloader_initProgressHandler);
+        for (var f:int = docFrame + 1; f < totalFrames; ++f)
+        {
+            addFrameScript(f, extraFrameHandler);
+        }
+        */
+
+        initialize();
+        
+    }
+
+    private function docFrameListener(event:Event):void
+    {
+        if (currentFrame == 2)
+        {
+            removeEventListener(Event.ENTER_FRAME, docFrameListener);
+            if (totalFrames > 2)
+                addEventListener(Event.ENTER_FRAME, extraFrameListener);
+
+            docFrameHandler();
+        }
+    }
+
+    private function extraFrameListener(event:Event):void
+    {
+        if (lastFrame == currentFrame)
+            return;
+
+        lastFrame = currentFrame;
+
+        if (currentFrame + 1 > totalFrames)
+            removeEventListener(Event.ENTER_FRAME, extraFrameListener);
+
+        extraFrameHandler();
+    }
+
+    /**
+     *  @private
+     *  Once the swf has been fully downloaded,
+     *  advance the playhead to the next frame.
+     *  This will cause the framescript to run, which runs frameEndHandler().
+     */
+    private function preloader_initProgressHandler(event:Event):void
+    {
+        // Advance the next frame
+        preloader.removeEventListener(FlexEvent.INIT_PROGRESS,
+                                      preloader_initProgressHandler);
 
         deferredNextFrame();
-	}
-
-	/**
-	 *  @private
-	 *  Remove the preloader and add the application as a child.
-	 */
-	private function preloader_preloaderDoneHandler(event:Event):void
-	{
-		var app:IUIComponent = topLevelWindow;
-
-		// Once the preloader dispatches the PRELOADER_DONE event, remove the preloader
-		// and add the application as the child
-		preloader.removeEventListener(FlexEvent.PRELOADER_DONE,
-									  preloader_preloaderDoneHandler);
-
-		_popUpChildren.removeChild(preloader);
+    }
+
+    /**
+     *  @private
+     *  Remove the preloader and add the application as a child.
+     */
+    private function preloader_preloaderDoneHandler(event:Event):void
+    {
+        var app:IUIComponent = topLevelWindow;
+
+        // Once the preloader dispatches the PRELOADER_DONE event, remove the preloader
+        // and add the application as the child
+        preloader.removeEventListener(FlexEvent.PRELOADER_DONE,
+                                      preloader_preloaderDoneHandler);
+
+        _popUpChildren.removeChild(preloader);
         preloader = null;
 
-		// Add the mouseCatcher as child 0.
-		mouseCatcher = new FlexSprite();
-		mouseCatcher.name = "mouseCatcher";
-		// Must use addChildAt because a creationComplete handler can create a
-		// dialog and insert it at 0.
-		noTopMostIndex++;
-		super.addChildAt(mouseCatcher, 0);	
-		resizeMouseCatcher();
-		if (!topLevel)
-		{
-			mouseCatcher.visible = false;
-			mask = mouseCatcher;
-		}
-
-		// Add the application as child 1.
-		noTopMostIndex++;
-		super.addChildAt(DisplayObject(app), 1);
-		
-		// Dispatch the applicationComplete event from the Application
-		// and then agaom from the SystemManager
-		// (so that loading apps know we're done).
-		app.dispatchEvent(new FlexEvent(FlexEvent.APPLICATION_COMPLETE));
-		dispatchEvent(new FlexEvent(FlexEvent.APPLICATION_COMPLETE));
-	}
-
-	/**
-	 *  @private
-	 *  This is attached as the framescript at the end of frame 2.
-	 *  When this function is called, we know that the application
-	 *  class has been defined and read in by the Player.
-	 */
-	mx_internal function docFrameHandler(event:Event = null):void
-	{
-		// The ResourceManager has already been registered 
-		// by initialize() in frame 1.
-		
-		// Register other singleton classes.
-		// Note: getDefinitionByName() will return null
-		// if the class can't be found.
-
-		Singleton.registerClass("mx.managers::IBrowserManager",
-			Class(getDefinitionByName("mx.managers::BrowserManagerImpl")));
-
-		Singleton.registerClass("mx.managers::ICursorManager",
-			Class(getDefinitionByName("mx.managers::CursorManagerImpl")));
-
-		Singleton.registerClass("mx.managers::IHistoryManager",
-			Class(getDefinitionByName("mx.managers::HistoryManagerImpl")));
-
-		Singleton.registerClass("mx.managers::ILayoutManager",
-			Class(getDefinitionByName("mx.managers::LayoutManager")));
-
-		Singleton.registerClass("mx.managers::IPopUpManager",
-			Class(getDefinitionByName("mx.managers::PopUpManagerImpl")));
-
-		Singleton.registerClass("mx.managers::IToolTipManager2",
-			Class(getDefinitionByName("mx.managers::ToolTipManagerImpl")));
+        // Add the mouseCatcher as child 0.
+        mouseCatcher = new FlexSprite();
+        mouseCatcher.name = "mouseCatcher";
+        // Must use addChildAt because a creationComplete handler can create a
+        // dialog and insert it at 0.
+        noTopMostIndex++;
+        super.addChildAt(mouseCatcher, 0);  
+        resizeMouseCatcher();
+        if (!topLevel)
+        {
+            mouseCatcher.visible = false;
+            mask = mouseCatcher;
+        }
+
+        // Add the application as child 1.
+        noTopMostIndex++;
+        super.addChildAt(DisplayObject(app), 1);
+        
+        // Dispatch the applicationComplete event from the Application
+        // and then agaom from the SystemManager
+        // (so that loading apps know we're done).
+        app.dispatchEvent(new FlexEvent(FlexEvent.APPLICATION_COMPLETE));
+        dispatchEvent(new FlexEvent(FlexEvent.APPLICATION_COMPLETE));
+    }
+
+    /**
+     *  @private
+     *  This is attached as the framescript at the end of frame 2.
+     *  When this function is called, we know that the application
+     *  class has been defined and read in by the Player.
+     */
+    mx_internal function docFrameHandler(event:Event = null):void
+    {
+        // The ResourceManager has already been registered 
+        // by initialize() in frame 1.
+        
+        // Register other singleton classes.
+        // Note: getDefinitionByName() will return null
+        // if the class can't be found.
+
+        Singleton.registerClass("mx.managers::IBrowserManager",
+            Class(getDefinitionByName("mx.managers::BrowserManagerImpl")));
+
+        Singleton.registerClass("mx.managers::ICursorManager",
+            Class(getDefinitionByName("mx.managers::CursorManagerImpl")));
+
+        Singleton.registerClass("mx.managers::IHistoryManager",
+            Class(getDefinitionByName("mx.managers::HistoryManagerImpl")));
+
+        Singleton.registerClass("mx.managers::ILayoutManager",
+            Class(getDefinitionByName("mx.managers::LayoutManager")));
+
+        Singleton.registerClass("mx.managers::IPopUpManager",
+            Class(getDefinitionByName("mx.managers::PopUpManagerImpl")));
+
+        Singleton.registerClass("mx.managers::IToolTipManager2",
+            Class(getDefinitionByName("mx.managers::ToolTipManagerImpl")));
 
         var dragManagerClass:Class = null;
-				
-			// Make this call to create a new instance of the DragManager singleton. 
+                
+            // Make this call to create a new instance of the DragManager singleton. 
         // Try to link in the NativeDragManager first. This will allow the  
         // application to receive NativeDragEvents that originate from the
         // desktop.  If it can't be found, then we're 

        }
    }

	private function installCompiledResourceBundles():void
	{
		var info:Object = this.info();
		
		var applicationDomain:ApplicationDomain =
			!topLevel && parent is Loader ?
			Loader(parent).contentLoaderInfo.applicationDomain :
            info["currentDomain"];

		var compiledLocales:Array /* of String */ =
			info["compiledLocales"];

		var compiledResourceBundleNames:Array /* of String */ =
			info["compiledResourceBundleNames"];
		
		var resourceManager:IResourceManager =
			ResourceManager.getInstance();
		
		resourceManager.installCompiledResourceBundles(
			applicationDomain, compiledLocales, compiledResourceBundleNames);

		// If the localeChain wasn't specified in the FlashVars of the SWF's
		// HTML wrapper, or in the query parameters of the SWF URL,
		// then initialize it to the list of compiled locales,
        // sorted according to the system's preferred locales as reported by
        // Capabilities.languages or Capabilities.language.
		// For example, if the applications was compiled with, say,
		// -locale=en_US,ja_JP and Capabilities.languages reports [ "ja-JP" ],
        // set the localeChain to [ "ja_JP" "en_US" ].
		if (!resourceManager.localeChain)
			resourceManager.initializeLocaleChain(compiledLocales);
	}

	private function extraFrameHandler(event:Event = null):void
	{
	    var frameList:Object = info()["frames"];

	    if (frameList && frameList[currentLabel])
	    {
	        var c:Class = Class(getDefinitionByName(frameList[currentLabel]));
	        c["frame"](this);
	    }

	    deferredNextFrame();
	}

    /**
	 *  @private
	 */
	private function nextFrameTimerHandler(event:TimerEvent):void
	{
	    if (currentFrame + 1 <= framesLoaded)
	    {
	        nextFrame();
            nextFrameTimer.removeEventListener(TimerEvent.TIMER, nextFrameTimerHandler);
        	// stop the timer
        	nextFrameTimer.reset();
        }
    }
	
	/**
	 *  @private
	 *  Instantiates an instance of the top level window
	 *  and adds it as a child of the SystemManager.
	 */
	private function initializeTopLevelWindow(event:Event):void
	{
		initialized = true;

		// Parent may be null if in another sandbox and don't have
		// access to our parent.  Add a check for this case.
		if (!parent && parentAllowsChild)
			return;
		
		if (!topLevel)
		{
            // We are not top-level and don't have a parent. This can happen
            // when the application has already been unloaded by the time
            // we get to this point.
            if (!parent)
                return;

			var obj:DisplayObjectContainer = parent.parent;

  			// if there is no grandparent at this point, we might have been removed and
  			// are about to be killed so just bail.  Other code that runs after
  			// this point expects us to be grandparented.  Another scenario
  			// is that someone loaded us but not into a parented loader, but that
  			// is not allowed.
  			if (!obj)
  				return;
  
			while (obj)
			{
				if (obj is IUIComponent)
				{
					var sm:ISystemManager = IUIComponent(obj).systemManager;
					if (sm && !sm.isTopLevel())
						sm = sm.topLevelSystemManager;
						
					_topLevelSystemManager = sm;
					break;
				}
				obj = obj.parent;
			}
		}

		// capture mouse down so we can switch top level windows and activate
		// the right focus manager before the components inside start
		// processing the event
		if (isTopLevelRoot() || getSandboxRoot() == this)
		addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler, true); 

		if (isTopLevelRoot() && stage)
		 	stage.addEventListener(Event.RESIZE, Stage_resizeHandler, false, 0, true);
		else if (topLevel && stage)
		{
			// listen to resizes on the sandbox root
			var sandboxRoot:DisplayObject = getSandboxRoot();
			if (sandboxRoot != this)
				sandboxRoot.addEventListener(Event.RESIZE, Stage_resizeHandler, false, 0, true);
		}

		var app:IUIComponent;
		// Create a new instance of the toplevel class
        document = app = topLevelWindow = IUIComponent(create());

		if (document)
		{
			// Add listener for the creationComplete event
			IEventDispatcher(app).addEventListener(FlexEvent.CREATION_COMPLETE,
												   appCreationCompleteHandler);

			// if somebody has set this in our applicationdomain hierarchy, don't overwrite it
			if (!LoaderConfig._url)
			{
				LoaderConfig._url = loaderInfo.url;
				LoaderConfig._parameters = loaderInfo.parameters;
			}
				
			if (isStageRoot && stage)
			{
				// stageWidth/stageHeight may have changed between initialize() and now,
				// so refresh our _width and _height here. 
				_width = stage.stageWidth;
				_height = stage.stageHeight;
				
				IFlexDisplayObject(app).setActualSize(_width, _height);
			}
			else
				IFlexDisplayObject(app).setActualSize(loaderInfo.width, loaderInfo.height);

			// Wait for the app to finish its initialization sequence
			// before doing an addChild(). 
			// Otherwise, the measurement/layout code will cause the
			// player to do a bunch of unnecessary screen repaints,
			// which slows application startup time.
			
			// Pass the application instance to the preloader.
			// Note: preloader can be null when the user chooses
			// Control > Play in the standalone player.
			if (preloader)
				preloader.registerApplication(app);
						
			// The Application doesn't get added to the SystemManager in the standard way.
			// We want to recursively create the entire application subtree and process
			// it with the LayoutManager before putting the Application on the display list.
			// So here we what would normally happen inside an override of addChild().
			// Leter, when we actually attach the Application instance,
			// we call super.addChild(), which is the bare player method.
			addingChild(DisplayObject(app));
			childAdded(DisplayObject(app)); // calls app.createChildren()
		}
		else
		{
			document = this;
		}
	}
	
 	/**
	 *  Override this function if you want to perform any logic
	 *  when the application has finished initializing itself.
	 *  
	 *  @langversion 3.0
	 *  @playerversion Flash 9
	 *  @playerversion AIR 1.1
	 *  @productversion Flex 3
	 */
	private function appCreationCompleteHandler(event:FlexEvent):void
	{
		if (!topLevel && parent)
		{
			var obj:DisplayObjectContainer = parent.parent;
			while (obj)
			{
				if (obj is IInvalidating)
				{
					IInvalidating(obj).invalidateSize();
					IInvalidating(obj).invalidateDisplayList();
					return;
				}
				obj = obj.parent;
			}
		}
 
		if (topLevel && useSWFBridge())
		   dispatchInvalidateRequest();
	}

	/**
	 *  @private
	 *  Keep track of the size and position of the stage.
	 */
	private function Stage_resizeHandler(event:Event = null):void
	{	
		if (isDispatchingResizeEvent)
			return;

                var w:Number = 0;
                var h:Number = 0;

        // forward request 
        if (!isTopLevelRoot())
        { 
            var bridge:IEventDispatcher = swfBridgeGroup.parentBridge;
            request.requestor = bridge;
            bridge.dispatchEvent(request);
        }
        else if (eventProxy)
            SystemManagerGlobals.showMouseCursor = true;
        
    }

    private function resetMouseCursorTracking(event:Event):void
    {
        if (isTopLevelRoot())
        {
            SystemManagerGlobals.showMouseCursor = true;
        }
        else if (swfBridgeGroup.parentBridge)
        {
            var cursorRequest:SWFBridgeRequest = new SWFBridgeRequest(SWFBridgeRequest.RESET_MOUSE_CURSOR_REQUEST);
            var bridge:IEventDispatcher = swfBridgeGroup.parentBridge;
            cursorRequest.requestor = bridge;
            bridge.dispatchEvent(cursorRequest);
        }

    }

    //--------------------------------------------------------------------------
    //
    //  Sandbox Event handlers for messages from parent
    //
    //--------------------------------------------------------------------------
    
    /**
     * @private
     * 
     * Sent by the SWFLoader to change the size of the application it loaded.
     */
    private function setActualSizeRequestHandler(event:Event):void
    {
        var eObj:Object = Object(event);
        setActualSize(eObj.data.width, eObj.data.height);
    }
    
    /**
     * @private
     * 
     * Get the size of this System Manager.
     * Sent by a SWFLoader.
     */
    private function getSizeRequestHandler(event:Event):void
    {
        var eObj:Object = Object(event);
        eObj.data = { width: measuredWidth, height: measuredHeight};                    
    }
    
    /**
     * @private
     * 
     * Handle request to activate a particular form.
     * 
     */
    private function activateRequestHandler(event:Event):void
    {
        var request:SWFBridgeRequest = SWFBridgeRequest.marshal(event);

        // If data is a String, then we need to parse the id to find
        // the form or the next bridge to pass the message to.
        // If the data is a SystemMangerProxy we can just activate the
        // form.
        var child:Object = request.data; 
        var nextId:String = null;
        if (request.data is String)
        {
            var placeholder:PlaceholderData = idToPlaceholder[request.data];
            child = placeholder.data;
            nextId = placeholder.id;
            
            // check if the dialog is hosted on this system manager
            if (nextId == null)
            {
                var popUp:RemotePopUp = findRemotePopUp(child, placeholder.bridge); 
                
                if (popUp)
                {
                    activateRemotePopUp(popUp);
                    return;
                }
            }
        }
        
        if (child is SystemManagerProxy)
        {
            // activate request from the top-level system manager.
            var smp:SystemManagerProxy = SystemManagerProxy(child);
            var f:IFocusManagerContainer = findFocusManagerContainer(smp);
            if (smp && f)
                smp.activateByProxy(f);
        }   
        else if (child is IFocusManagerContainer)
            IFocusManagerContainer(child).focusManager.activate();
        else if (child is IEventDispatcher)
        {
                request.data = nextId;
                request.requestor = IEventDispatcher(child);
                IEventDispatcher(child).dispatchEvent(request);
        }
        else 
            throw new Error();  // should never get here
    }

    /**
     * @private
     * 
     * Handle request to deactivate a particular form.
     * 
     */
    private function deactivateRequestHandler(event:Event):void
    {
        var request:SWFBridgeRequest = SWFBridgeRequest.marshal(event);
        var child:Object = request.data; 
        var nextId:String = null;
        if (request.data is String)
        {
            var placeholder:PlaceholderData = idToPlaceholder[request.data];
            child = placeholder.data;
            nextId = placeholder.id;

            // check if the dialog is hosted on this system manager
            if (nextId == null)
            {
                var popUp:RemotePopUp = findRemotePopUp(child, placeholder.bridge); 
                
                if (popUp)
                {
                    deactivateRemotePopUp(popUp);
                    return;
                }
            }
        }
        
        if (child is SystemManagerProxy)
        {
            // deactivate request from the top-level system manager.
            var smp:SystemManagerProxy = SystemManagerProxy(child);
            var f:IFocusManagerContainer = findFocusManagerContainer(smp);
            if (smp && f)
                smp.deactivateByProxy(f);
        }
        else if (child is IFocusManagerContainer)
            IFocusManagerContainer(child).focusManager.deactivate();
            
        else if (child is IEventDispatcher)
        {
            request.data = nextId;
            request.requestor = IEventDispatcher(child);
            IEventDispatcher(child).dispatchEvent(request);
            return;
        }
        else
            throw new Error();      
    }

    //--------------------------------------------------------------------------
    //
    //  Sandbox Event handlers for messages from either the
    //  parent or child
    //
    //--------------------------------------------------------------------------

    /**
     * Is the child in event.data this system manager or a child of this 
     * system manager?
     *
     * Set the data property to indicate if the display object is a child
     *  
     *  @langversion 3.0
     *  @playerversion Flash 9
     *  @playerversion AIR 1.1
     *  @productversion Flex 3
     */
    private function isBridgeChildHandler(event:Event):void
    {
        // if we are broadcasting messages, ignore the messages
        // we send to ourselves.
        if (event is SWFBridgeRequest)
            return;

        var eObj:Object = Object(event);

        eObj.data = eObj.data && rawChildren.contains(eObj.data as DisplayObject);
    }
    
    /**
     * Can this form be activated. The current test is if the given pop up 
     * is visible and is enabled. 
     *
     * Set the data property to indicate if can be activated
     *  
     *  @langversion 3.0
     *  @playerversion Flash 9
     *  @playerversion AIR 1.1
     *  @productversion Flex 3
     */
    private function canActivateHandler(event:Event):void
    {
        var eObj:Object = Object(event);

        // If data is a String, then we need to parse the id to find
        // the form or the next bridge to pass the message to.
        // If the data is a SystemMangerProxy we can just activate the
        // form.
        var request:SWFBridgeRequest;
        var child:Object = eObj.data; 
        var nextId:String = null;
        if (eObj.data is String)
        {
            var placeholder:PlaceholderData = idToPlaceholder[eObj.data];
            child = placeholder.data;
            nextId = placeholder.id;
            
            // check if the dialog is hosted on this system manager
            if (nextId == null)
            {
                var popUp:RemotePopUp = findRemotePopUp(child, placeholder.bridge); 
                
                if (popUp)
                {
                    request = new SWFBridgeRequest(SWFBridgeRequest.CAN_ACTIVATE_POP_UP_REQUEST,
                                                                false, false, 
                                                                IEventDispatcher(popUp.bridge), 
                                                                popUp.window);
                    if (popUp.bridge)
                    {
                        popUp.bridge.dispatchEvent(request);
                        eObj.data = request.data;
                    }
                    return;
                }
            }
        }
        
        if (child is SystemManagerProxy)
        {
            var smp:SystemManagerProxy = SystemManagerProxy(child);
            var f:IFocusManagerContainer = findFocusManagerContainer(smp);
            eObj.data = smp && f && canActivateLocalComponent(f);
        }   
        else if (child is IFocusManagerContainer)
        {
            eObj.data = canActivateLocalComponent(child);
        }
        else if (child is IEventDispatcher)
        {
            var bridge:IEventDispatcher = IEventDispatcher(child);
            request = new SWFBridgeRequest(SWFBridgeRequest.CAN_ACTIVATE_POP_UP_REQUEST,
                                                            false, false, 
                                                            bridge, 
                                                            nextId);
            
            if (bridge)
            {
                bridge.dispatchEvent(request);
                eObj.data = request.data;
            }
        }
        else 
            throw new Error();  // should never get here
    }
    

    /**
     * @private
     * 
     * Test if a display object is in an applcation we want to communicate with over a bridge.
     * 
     */
    public function isDisplayObjectInABridgedApplication(displayObject:DisplayObject):Boolean
    {
        return getSWFBridgeOfDisplayObject(displayObject) != null;
    }

