public virtual AsPoint localToGlobal(AsPoint localPoint)
        {
            sTargetMatrix.identity();
            AsDisplayObject currentObject = this;

            while (currentObject != null)
            {
                currentObject.getTransformationMatrix(currentObject.mParent, sHelperMatrix);
                sTargetMatrix.concat(sHelperMatrix);
                currentObject = currentObject.getParent();
            }
            return(sTargetMatrix.transformPoint(localPoint));
        }
        public virtual AsMatrix getTransformationMatrix(AsDisplayObject targetSpace, AsMatrix resultMatrix)
        {
            if (resultMatrix != null)
            {
                resultMatrix.identity();
            }
            else
            {
                resultMatrix = new AsMatrix();
            }
            AsDisplayObject currentObject = this;

            if (targetSpace == this)
            {
                return(resultMatrix);
            }
            else
            {
                if (targetSpace == mParent || (targetSpace == null && mParent == null))
                {
                    if (mPivotX != 0.0f || mPivotY != 0.0f)
                    {
                        resultMatrix.translate(-mPivotX, -mPivotY);
                    }
                    if (mScaleX != 1.0f || mScaleY != 1.0f)
                    {
                        resultMatrix.scale(mScaleX, mScaleY);
                    }
                    if (mRotation != 0.0f)
                    {
                        resultMatrix.rotate(AsMathHelper.toRadians(mRotation));
                    }
                    if (mX != 0.0f || mY != 0.0f)
                    {
                        resultMatrix.translate(mX, mY);
                    }
                    return(resultMatrix);
                }
                else
                {
                    if (targetSpace == null)
                    {
                        currentObject = this;
                        while (currentObject != null)
                        {
                            currentObject.getTransformationMatrix(currentObject.mParent, sHelperMatrix);
                            resultMatrix.concat(sHelperMatrix);
                            currentObject = currentObject.getParent();
                        }
                        return(resultMatrix);
                    }
                    else
                    {
                        if (targetSpace.mParent == this)
                        {
                            targetSpace.getTransformationMatrix(this, resultMatrix);
                            resultMatrix.invert();
                            return(resultMatrix);
                        }
                    }
                }
            }
            sAncestors.setLength(0);
            AsDisplayObject commonParent = null;

            while (currentObject != null)
            {
                sAncestors.push(currentObject);
                currentObject = currentObject.getParent();
            }
            currentObject = targetSpace;
            while (currentObject != null && sAncestors.indexOf(currentObject) == -1)
            {
                currentObject = currentObject.getParent();
            }
            if (currentObject == null)
            {
                throw new AsArgumentError("Object not connected to target");
            }
            else
            {
                commonParent = currentObject;
            }
            currentObject = this;
            while (currentObject != commonParent)
            {
                currentObject.getTransformationMatrix(currentObject.mParent, sHelperMatrix);
                resultMatrix.concat(sHelperMatrix);
                currentObject = currentObject.getParent();
            }
            sTargetMatrix.identity();
            currentObject = targetSpace;
            while (currentObject != commonParent)
            {
                currentObject.getTransformationMatrix(currentObject.mParent, sHelperMatrix);
                sTargetMatrix.concat(sHelperMatrix);
                currentObject = currentObject.getParent();
            }
            sTargetMatrix.invert();
            resultMatrix.concat(sTargetMatrix);
            return(resultMatrix);
        }
 public virtual AsMatrix getTransformationMatrix(AsDisplayObject targetSpace, AsMatrix resultMatrix)
 {
     if(resultMatrix != null)
     {
         resultMatrix.identity();
     }
     else
     {
         resultMatrix = new AsMatrix();
     }
     AsDisplayObject currentObject = this;
     if(targetSpace == this)
     {
         return resultMatrix;
     }
     else
     {
         if(targetSpace == mParent || (targetSpace == null && mParent == null))
         {
             if(mPivotX != 0.0f || mPivotY != 0.0f)
             {
                 resultMatrix.translate(-mPivotX, -mPivotY);
             }
             if(mScaleX != 1.0f || mScaleY != 1.0f)
             {
                 resultMatrix.scale(mScaleX, mScaleY);
             }
             if(mRotation != 0.0f)
             {
                 resultMatrix.rotate(AsMathHelper.toRadians(mRotation));
             }
             if(mX != 0.0f || mY != 0.0f)
             {
                 resultMatrix.translate(mX, mY);
             }
             return resultMatrix;
         }
         else
         {
             if(targetSpace == null)
             {
                 currentObject = this;
                 while(currentObject != null)
                 {
                     currentObject.getTransformationMatrix(currentObject.mParent, sHelperMatrix);
                     resultMatrix.concat(sHelperMatrix);
                     currentObject = currentObject.getParent();
                 }
                 return resultMatrix;
             }
             else
             {
                 if(targetSpace.mParent == this)
                 {
                     targetSpace.getTransformationMatrix(this, resultMatrix);
                     resultMatrix.invert();
                     return resultMatrix;
                 }
             }
         }
     }
     sAncestors.setLength(0);
     AsDisplayObject commonParent = null;
     while(currentObject != null)
     {
         sAncestors.push(currentObject);
         currentObject = currentObject.getParent();
     }
     currentObject = targetSpace;
     while(currentObject != null && sAncestors.indexOf(currentObject) == -1)
     {
         currentObject = currentObject.getParent();
     }
     if(currentObject == null)
     {
         throw new AsArgumentError("Object not connected to target");
     }
     else
     {
         commonParent = currentObject;
     }
     currentObject = this;
     while(currentObject != commonParent)
     {
         currentObject.getTransformationMatrix(currentObject.mParent, sHelperMatrix);
         resultMatrix.concat(sHelperMatrix);
         currentObject = currentObject.getParent();
     }
     sTargetMatrix.identity();
     currentObject = targetSpace;
     while(currentObject != commonParent)
     {
         currentObject.getTransformationMatrix(currentObject.mParent, sHelperMatrix);
         sTargetMatrix.concat(sHelperMatrix);
         currentObject = currentObject.getParent();
     }
     sTargetMatrix.invert();
     resultMatrix.concat(sTargetMatrix);
     return resultMatrix;
 }