 	}
 	
 	
-	
-	
-
-	
 	/**
 	 * @private
 	 * convenience function for building a 2D matrix from the convenience properties 

	private static const RADIANS_PER_DEGREES:Number = Math.PI / 180;

	private static const ZERO_REPLACEMENT_IN_3D:Number = .00000000000001;
	
	//------------------------------------------------------------------------------
	

						

	/**
	 * A utility method to update the rotation and scale of the transform 
	 * while keeping a particular point, specified in the component's 
	 * own coordinate space, fixed in the parent's coordinate space.  
	 * This function will assign the rotation and scale values provided, 
	 * then update the x/y/z properties as necessary to keep tx/ty/tz fixed.
	 * @param rx,ry,rz the new values for the rotation of the transform
	 * @param sx,sy,sz the new values for the scale of the transform
	 * @param tx,ty,tz the point, in the component's own coordinates, 
	 * to keep fixed relative to its parent.
	 */
    public function transformPointToParent(propertyIs3D:Boolean,
        transformCenter:Vector3D, currentPosition:Vector3D,
        currentPostLayoutPosition:Vector3D):void
    {
        var computedCenterV:Vector3D;
        var token:Object = {};
        tempTransformCenter = 
            transformCenter ?
            transformCenter :
            new Vector3D();
                
        if (is3D || propertyIs3D) 
        {
            if (currentPosition != null)
            {
                var layoutCenterV:Vector3D = 
                    layoutMatrix3D.transformVector(tempTransformCenter);
                layoutCenterV.project();
                currentPosition.x = layoutCenterV.x;
                currentPosition.y = layoutCenterV.y;
                currentPosition.z = layoutCenterV.z;
            } 
            
            if (currentPostLayoutPosition != null && _offsets != null)
            {           
                computedCenterV = computedMatrix3D.transformVector(tempTransformCenter);
                computedCenterV.project();
                currentPostLayoutPosition.x = computedCenterV.x;
                currentPostLayoutPosition.y = computedCenterV.y;
                currentPostLayoutPosition.z = computedCenterV.z;
            }
        }
        else
        {
            var centerP:Point = new Point(tempTransformCenter.x, 
                tempTransformCenter.y);
            if (currentPosition != null)
            {
            
                var currentPositionPt:Point = layoutMatrix.transformPoint(centerP);
                currentPostLayoutPosition.x = currentPositionPt.x;
                currentPostLayoutPosition.y = currentPositionPt.y;
                currentPostLayoutPosition.z = 0;
            }
            
            if (currentPostLayoutPosition != null && _offsets != null)
            {
                currentPositionPt = computedMatrix.transformPoint(centerP);
                currentPostLayoutPosition.x = currentPositionPt.x;
                currentPostLayoutPosition.y = currentPositionPt.y;
                currentPostLayoutPosition.z = 0;
            }
        }
    }

    /**
     * @private
     * call when you've changed the inputs to the computed transform to make 
     * any adjustments to keep a particular point fixed in parent coordinates.
     */
    private function completeTransformCenterAdjustment(changeIs3D:Boolean, 
        transformCenter:Vector3D, targetPosition:Vector3D,
        targetPostLayoutPosition:Vector3D):void
    {
        
        if (is3D || changeIs3D)
        {
            if (targetPosition != null)
            {
                var adjustedLayoutCenterV:Vector3D = 
                    layoutMatrix3D.transformVector(transformCenter);
                adjustedLayoutCenterV.project();
                if(adjustedLayoutCenterV.equals(targetPosition) == false)
                {
                    layout.translateBy(targetPosition.x - adjustedLayoutCenterV.x,
                        targetPosition.y - adjustedLayoutCenterV.y, 
                        targetPosition.z - adjustedLayoutCenterV.z);
                    invalidate(); 
                }       
            }
            if (targetPostLayoutPosition != null && _offsets != null)
            {
                var adjustedComputedCenterV:Vector3D = 
                    computedMatrix3D.transformVector(transformCenter);
                adjustedComputedCenterV.project();
                if (adjustedComputedCenterV.equals(targetPostLayoutPosition) == false)
                {
                    offsets.x +=targetPostLayoutPosition.x - adjustedComputedCenterV.x;
                    offsets.y += targetPostLayoutPosition.y - adjustedComputedCenterV.y;
                    offsets.z += targetPostLayoutPosition.z - adjustedComputedCenterV.z;
                    invalidate(); 
                }       
            }
        }
        else
        {
            var transformCenterP:Point = new Point(transformCenter.x,transformCenter.y);
            if (targetPosition != null)
            {
                var currentPositionP:Point = layoutMatrix.transformPoint(transformCenterP);
                if (currentPositionP.x != targetPosition.x || 
                    currentPositionP.y != targetPosition.y)
                {
                    layout.translateBy(targetPosition.x - currentPositionP.x,
                        targetPosition.y - currentPositionP.y, 0);
                    invalidate(); 
                }       
            }
            
            if (targetPostLayoutPosition != null && _offsets != null)
            {           
                var currentPostLayoutPosition:Point = 
                    computedMatrix.transformPoint(transformCenterP);
                if (currentPostLayoutPosition.x != targetPostLayoutPosition.x || 
                    currentPostLayoutPosition.y != targetPostLayoutPosition.y)
                {
                    _offsets.x += targetPostLayoutPosition.x - currentPostLayoutPosition.x;
                    _offsets.y += targetPostLayoutPosition.y - currentPostLayoutPosition.y;
                    invalidate(); 
                }       
            }
        }
    }   
    
    private static var staticTranslation:Vector3D = new Vector3D();
    private static var staticOffsetTranslation:Vector3D = new Vector3D();
    
    /**
     * A utility method to update the rotation and scale of the transform 
     * while keeping a particular point, specified in the component's own 
     * coordinate space, fixed in the parent's coordinate space.  This 
     * function will assign the rotation and scale values provided, then 
     * update the x/y/z properties as necessary to keep tx/ty/tz fixed.
     * @param transformCenter the point, in the component's own coordinates, 
     * to keep fixed relative to its parent.
     * @param rotation the new values for the rotation of the transform
     * @param scale the new values for the scale of the transform
     * @param translation the new values for the translation of the transform
     */
    public function transformAround(transformCenter:Vector3D,
                                    scale:Vector3D,
                                    rotation:Vector3D,
                                    translation:Vector3D,
                                    postLayoutScale:Vector3D = null,
                                    postLayoutRotation:Vector3D = null,
                                    postLayoutTranslation:Vector3D = null):void
    {
        var is3D:Boolean = (scale != null && scale.z != 1) ||
            (rotation != null && ((rotation.x != 0 ) || (rotation.y != 0))) || 
            (translation != null && translation.z != 0) ||
            (postLayoutScale != null && postLayoutScale.z != 1) ||
            (postLayoutRotation != null && 
                (postLayoutRotation.x != 0 || postLayoutRotation.y != 0)) || 
            (postLayoutTranslation != null && postLayoutTranslation.z != 0);

        var needOffsets:Boolean = _offsets == null && 
            (postLayoutScale != null || postLayoutRotation != null || 
                postLayoutTranslation != null);
        if(needOffsets)
            _offsets = new TransformOffsets();                                               
                                                        
        // if transformCener is null, we can just set x/y/z, so we can short circuit this.
        var targetPosition:Vector3D = 
            (translation == null) ? 
            staticTranslation:
            null; 
        var postLayoutTargetPosition:Vector3D = 
            (postLayoutTranslation == null) ? 
            staticOffsetTranslation:
            null; 
        if (transformCenter != null && 
            (transformCenter.x != 0 || transformCenter.y != 0 || transformCenter.z != 0) &&
            (targetPosition != null || postLayoutTargetPosition != null))
        {           
            transformPointToParent(is3D, transformCenter, targetPosition,
                postLayoutTargetPosition);
        }
        if (targetPosition == null)
            targetPosition = translation;
        if (postLayoutTargetPosition == null)
            postLayoutTargetPosition = postLayoutTranslation;

        if (rotation != null)
        {
            if (!isNaN(rotation.x))
                layout.rotationX = rotation.x;
            if (!isNaN(rotation.y))
                layout.rotationY = rotation.y;
            if (!isNaN(rotation.z))
                layout.rotationZ = rotation.z;
        }
        if (scale != null)
        {           
            if (!isNaN(scale.x))
                layout.scaleX = scale.x;
            if (!isNaN(scale.y))
                layout.scaleY = scale.y;
            if (!isNaN(scale.z))
                layout.scaleZ = scale.z;
        }

        if (postLayoutRotation != null)
        {           
            _offsets.rotationX = postLayoutRotation.x;
            _offsets.rotationY = postLayoutRotation.y;
            _offsets.rotationZ = postLayoutRotation.z;
        }
        if (postLayoutScale != null)
        {           
            _offsets.scaleX = postLayoutScale.x;
            _offsets.scaleY = postLayoutScale.y;
            _offsets.scaleZ = postLayoutScale.z;
        }

        if (transformCenter == null)
        {
            if (translation != null)
            {
                layout.x = translation.x;
                layout.y = translation.y;
                layout.z = translation.z;
            }
            if (postLayoutTranslation != null)
            {
                _offsets.x = postLayoutTranslation.x;
                _offsets.y = postLayoutTranslation.y;
                _offsets.z = postLayoutTranslation.z;
            }
        }
        invalidate();
        if (transformCenter != null)
            completeTransformCenterAdjustment(is3D, transformCenter, 
                targetPosition, postLayoutTargetPosition);
        
    }
        
}
}

