     //
     //--------------------------------------------------------------------------
     
-    private var mirror:Boolean = false;
-    private var origMatrix:Matrix;
+    private var layoutFeatures:AdvancedLayoutFeatures;
     
     //--------------------------------------------------------------------------
     //

     */
    public function invalidateLayoutDirection():void
    {
        // We check the closest parent's layoutDirection property
        // set our mirror property and update our transform matrix
        // accordingly.
        var p:DisplayObjectContainer = parent;
        
        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) &&
                    (_layoutDirection != ILayoutDirectionElement(p).layoutDirection);
                
                if (mirror != oldMirror)
                {
                    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;
                    }
                }
                break;
            }
            

    
    /**
     *  @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;
        }
    }
}

