                     // and maskee to displayObject. 
                     if (!_mask.parent)
                     {
-                        Sprite(displayObject).addChild(_mask);   
-                        var maskComp:UIComponent = _mask as UIComponent;            
-                        if (maskComp)
-                        {
-                            if (parent)
-                            {
-                                // Add the mask to the UIComponent document tree. 
-                                // This is required to properly render the mask.
-                                UIComponent(parent).addingChild(maskComp);
-                                UIComponent(parent).childAdded(maskComp);
-                            }
-                            
-                            // Size the mask so that it actually renders
-                            maskComp.validateProperties();
-                            maskComp.validateSize();
-                            // Call this to force the mask to complete initialization
-                            maskComp.invalidateDisplayList();
-                            maskComp.setActualSize(maskComp.getExplicitOrMeasuredWidth(), 
-                                                   maskComp.getExplicitOrMeasuredHeight());
-                                                           
-                        }   
+                        MaskUtil.applyMask(_mask, parent);
+                        
+                        // Parent after applying the mask since it won't do
+                        // anything if there is a parent.
+                        Sprite(displayObject).addChild(_mask);  
                         
                         if (!_drawnDisplayObject)
                         {

import spark.core.DisplayObjectSharingMode;
import spark.core.IGraphicElement;
import spark.core.MaskType;

use namespace mx_internal;


        displayObject.transform.matrix3D = oldMat3D;

        return snapshot; 
    }

    /**
