- package
- {
- import flash.display.DisplayObject;
- import flash.display.Sprite;
- import flash.geom.Rectangle;
- public class DisplayObjectUtil
- {
-
- // Duplicate显示对象
- public static function duplicateDisplayObject( target:DisplayObject, auto_add:Boolean = false ):DisplayObject{
- var cls:Class = Object(target).constructor;
- var tmp:Sprite = new cls();
-
- // 克隆属性
- tmp.transform = target.transform;
- tmp.filters = target.filters;
- tmp.cacheAsBitmap = target.cacheAsBitmap;
- tmp.opaqueBackground = target.opaqueBackground;
- if ( target.scale9Grid ) {
- var rect:Rectangle = target.scale9Grid;
- tmp.scale9Grid = rect;
- }
-
- // 自动加为target的兄弟
- if ( auto_add && target.parent ) {
- target.parent.addChild( tmp );
- }
- return tmp;
- }
-
- }
- }