function cloneDisplayObject(target){
var targetClass:Class = Object(target).constructor
var duplicate = new targetClass() ;
duplicate.transform = target.transform;
duplicate.filters = target.filters;
duplicate.cacheAsBitmap = target.cacheAsBitmap;
duplicate.opaqueBackground = target.opaqueBackground;
if (target.scale9Grid) {
var rect:Rectangle = target.scale9Grid;
rect.x /= 20, rect.y /= 20, rect.width /= 20, rect.height /= 20;
duplicate.scale9Grid = rect;
}
if (target.hasOwnProperty("numChildren")){
for (var i = 0 ; i < target.numChildren; i ++) {
duplicate.addChild(cloneDisplayObject(target.getChildAt(i)));
}
}
return duplicate;
}
Flash/as3.0