Duplicate Display Object Bug & Workaround
Wayne Helman on June 28, 2009
No Comments
Since AS3 dropped support for the much loved AS2 duplicateMovieClip, most of us have been relying on a method posted by Senocular. While this works for the vast majority of instances, there are scenerios in which player 9 and 10 will crash trying to duplicate the transorm property. We identified this bug with the Adobe team and it is slated to be fixed. The simplest solution is to disable the duplication of the transform property by commenting out the line as below.
/** * duplicateDisplayObject * creates a duplicate of the DisplayObject passed. * similar to duplicateMovieClip in AVM1. * @param $target the display object to duplicate * @param $autoAdd if true, adds the duplicate to the display list * in which target was located * @return a duplicate instance of target */ public static function duplicateDisplayObject($target:DisplayObject, $autoAdd:Boolean = false):DisplayObject { var targetClass :Class = Object($target).constructor, duplicate :DisplayObject = new targetClass() as DisplayObject; //duplicate properties causes player to crash - disable //duplicate.transform = $target.transform; duplicate.filters = $target.filters; duplicate.cacheAsBitmap = $target.cacheAsBitmap; duplicate.opaqueBackground = $target.opaqueBackground; if ($target.scale9Grid) { var rect:Rectangle = $target.scale9Grid; if (Capabilities.version.split(" ")[1] == "9,0,16,0") { //another Flash 9 bug where returned scale9Grid as twips - not what we're refering to! rect.x /= 20, rect.y /= 20, rect.width /= 20, rect.height /= 20; } duplicate.scale9Grid = rect; } if ($autoAdd && $target.parent) { $target.parent.addChild(duplicate); } return duplicate; }
