             // clipped/obscured by the soft keyboard
             var topLevelApp:Application = FlexGlobals.topLevelApplication as Application;
             var eltBounds:Rectangle;
-            var adjustForSoftKeyboard:Boolean = topLevelApp && 
+            var adjustForSoftKeyboard:Boolean = topLevelApp &&
                                                 (!topLevelApp.resizeForSoftKeyboard) &&
-                                                (stage.softKeyboardRect.height > 0);
+                                                (stage && stage.softKeyboardRect.height > 0);
             
             if (adjustForSoftKeyboard)
             {

    private function snapContentScrollPosition(snapHorizontal:Boolean = true, snapVertical:Boolean = true):void
    {
        if (snapHorizontal)
    {
        viewport.horizontalScrollPosition = getSnappedPosition( 
            Math.min(Math.max(minHorizontalScrollPosition, viewport.horizontalScrollPosition), maxHorizontalScrollPosition),
            HORIZONTAL_SCROLL_POSITION);
        }

        if (snapVertical)
        {
        viewport.verticalScrollPosition = getSnappedPosition( 
            Math.min(Math.max(minVerticalScrollPosition, viewport.verticalScrollPosition), maxVerticalScrollPosition),
            VERTICAL_SCROLL_POSITION);
    }
    }
    
    /**

                        else if (viewport.horizontalScrollPosition + width < eltBounds.right + focusThickness)
                            viewport.horizontalScrollPosition = eltBounds.right + focusThickness - width;
                    }
                }
                
                if (doValidateNow && viewport is UIComponent)
