      */
     public function invalidateLayoutDirection():void
     {
+        var p:DisplayObjectContainer = parent;
+
         // We check the closest parent's layoutDirection property
-        // set our mirror property and update our transform matrix
-        // accordingly.
-        var p:DisplayObjectContainer = parent;
-        
+        // to create or destroy layoutFeatures if needed.
         while (p)
         {
             if (p is ILayoutDirectionElement)
             {
-                // If this element's layoutDirection doesn't match its parent's, then
-                // set the mirror flag.
-                const oldMirror:Boolean = mirror;
-                mirror = (_layoutDirection != null) &&
+                // mirror is true if our layoutDirection differs from our parent's.
+                var mirror:Boolean = (_layoutDirection != null) &&
                     (_layoutDirection != ILayoutDirectionElement(p).layoutDirection);
                 
-                if (mirror != oldMirror)
+                // If our layoutDirection is different from our parent's and if it used to
+                // be the same, create layoutFeatures to handle mirroring.
+                if (mirror && layoutFeatures == null)
                 {
-                    if (mirror)
-                    {
-                        // Set backing variables to current state
-                        _scaleX = super.scaleX;
-                        _scaleY = super.scaleY;
-                        _x = super.x;
-                        validateTransformMatrix();
-                    }
-                    else
-                    {
-                        // origMatrix has been initialized in validateTransformMatrix
-                        // because we weren't matching our parent's layoutDirection before.
-                        transform.matrix = origMatrix;
-                    }
+                    initAdvancedLayoutFeatures();
+                    layoutFeatures.mirror = mirror;
+                    validateTransformMatrix();
                 }
+                else if (!mirror && layoutFeatures)
+                {
+                    // If our layoutDirection is not different from our parent's and if
+                    // it used to be different, then recover our matrix and remove layoutFeatures.
+                    layoutFeatures.mirror = mirror;
+                    validateTransformMatrix();
+                    layoutFeatures = null;
+                }
+                
                 break;
             }
             

    /**
     *  @private
     */
    override public function set width(value:Number):void
    {
        if (mirror)
        {
            transform.matrix = origMatrix;
            super.width = value;
            // Store new scaleX/Y since setting width may modify them
            _scaleX = super.scaleX;
            _scaleY = super.scaleY;
            validateTransformMatrix();
        }
        else
        {
            super.width = value;
        }
    }
    

    
    /**
     *  @private
     *  Initializes AdvancedLayoutFeatures for this asset when mirroring.
     */
    private function initAdvancedLayoutFeatures():void
    {
        var features:AdvancedLayoutFeatures = new AdvancedLayoutFeatures();
        
        features.layoutScaleX = scaleX;
        features.layoutScaleY = scaleY;
        features.layoutScaleZ = scaleZ;
        features.layoutRotationX = rotationX;
        features.layoutRotationY = rotationY;
        features.layoutRotationZ = rotation;
        features.layoutX = x;
        features.layoutY = y;
        features.layoutZ = z;
        features.layoutWidth = width;  // for the mirror transform
        _height = height;  // for backing storage
        layoutFeatures = features;
    }
    
    /**
     *  @private
     *  Applies the transform matrix calculated by AdvancedLayoutFeatures 
     *  so that this bitmap will not be mirrored if a parent is mirrored.
     */
    private function validateTransformMatrix():void
    {
        if (layoutFeatures != null)
        {
            if (layoutFeatures.is3D)
                super.transform.matrix3D = layoutFeatures.computedMatrix3D;
            else
                super.transform.matrix = layoutFeatures.computedMatrix;
        }
    }
}

