         // orientation on their own.
         if (isNaN(explicitWidth) && isNaN(explicitHeight))
         { 
-            if (!cachedSizes)
-                cachedSizes = {};
+            if (!cachedDimensions)
+                cachedDimensions = new Dictionary();
             
-            // Cache the current percentWidth and height values.  These will
-            // be lost when width and height are set, and restored later.            
-            cachedSizes.oldPercentWidth = percentWidth;
-            cachedSizes.oldPercentHeight = percentHeight;
-
-            // If the application is currently in landscape orientation
-            if (sm.stage.stageWidth > sm.stage.stageHeight)
+            // remember the current dimensions
+            previousWidth = width;
+            previousHeight = height;
+            
+            var key:String = width + ":" + height;
+            
+            // On some platforms (e.g. iOS and Playbook) if the soft keyboard is up
+            // it deactivates before orientation change and reactivates after it; 
+            // the value of isSoftKeyboardActive thus changes during orientation change.
+            // We are remembering the initial value of isSoftKeyboardActivate in this
+            // situation for use in avoiding excessive resizing during the orientation change.
+            keyboardActiveInOrientationChange = isSoftKeyboardActive;
+
+            // if we're rotating 180 degrees don't do any screen resizing
+            var beforeOrientation:String = event["beforeOrientation"];
+            var afterOrientation:String = event["afterOrientation"];
+            
+            if ((beforeOrientation == "default" && afterOrientation == "upsideDown") ||
+                (beforeOrientation == "upsideDown" && afterOrientation == "default") ||
+                (beforeOrientation == "rotatedLeft" && afterOrientation == "rotatedRight") ||
+                (beforeOrientation == "rotatedRight" && afterOrientation == "rotatedLeft"))
+                return;
+
+            var newWidth:Number;
+            var newHeight:Number;
+
+            // if we have a cached value, use it
+            if (cachedDimensions[key])
             {
-                if (!cachedSizes.landscapeWidth)
-                {
-                    cachedSizes.landscapeWidth = width;
-                    cachedSizes.landscapeHeight = height;
-                }
-                
-                // If the size for portrait has been saved, use it.  Otherwise
-                // just swap width and height
-                if (cachedSizes.portraitWidth)
-                {
-                    width = cachedSizes.portraitWidth;
-                    height = cachedSizes.portraitHeight;
-                }
-                else
-                    swapApplicationDimensions();
+                newWidth = cachedDimensions[key].width;
+                newHeight = cachedDimensions[key].height;
             }
-            else
+            else // no cached value; just swap the numbers for now
             {
-                if (!cachedSizes.portraitWidth)
-                {
-                    cachedSizes.portraitWidth = width;
-                    cachedSizes.portraitHeight = height;
-                }
-                
-                // If the size for landscape has been saved, use it.  Otherwise
-                // just swap width and height
-                if (cachedSizes.landscapeWidth)
-                {
-                    width = cachedSizes.landscapeWidth;
-                    height = cachedSizes.landscapeHeight;
-                }
-                else
-                    swapApplicationDimensions();
+                // use stageHeight as the new width if you can get it
+                newWidth = stage ? stage.stageHeight / scaleFactor : height;
+                newHeight = width;
             }
             
-            // Indicate that the width and heigth have changed because of orientation 
-            restoreApplicationWidthAndHeight = true;
+            setActualSize(newWidth, newHeight);
+            
+            // Indicate that the width and height have changed because of orientation 
+            explicitSizingForOrientation = true;
             
             // Force a validation
             validateNow();
         }
-    }
-    
-    /**
-     *  @private
-     *  Swaps the applications width and height
-     */ 
-    private function swapApplicationDimensions():void
-    {
-        var tmp:Number = width;
-        width = height;
-        height = tmp;
     }
     
     /**

import flash.system.Capabilities;
import flash.ui.ContextMenu;
import flash.ui.ContextMenuItem;
import flash.utils.setInterval;

import mx.core.EventPriority;

     *  Flag set to true if the application has temporarily set its explicit
     *  width and height to deal with orientation.
     */ 
    private var explicitSizingForOrientation:Boolean = false;
    
    /**
     *  @private
     *  Caches the application's width and height values for better resizing
     *  of the screen during orientation changes. Keys are composed of the width and
     *  height values in a string of the form "w:h", e.g. "1004:768" and represent
     *  the screen dimensions before the orientation change. Values are
     *  objects containing width and height properties that represent the screen dimensions
     *  after the orientation change.
     */
    private var cachedDimensions:Dictionary;
    
    /**
     *  @private
     *  Previous width of the application prior to an orientation change 
     */    
    private var previousWidth:Number;
    
    /**
     *  @private
     *  Previous height of the application prior to an orientation change 
     */    
    private var previousHeight:Number;
    
    /**
     *  @private
     *  Flag to determine if the keyboard is active during an orientation change,
     *  to minimize renders during the orientation change.
     */
    private var keyboardActiveInOrientationChange:Boolean = false;
    
    /**
     *  @private
