Jump to content
GreenSock

Search In
  • More options...
Find results that contain...
Find results in...
overbyte

duplicating a loaded swf

Recommended Posts

hey folks

 

i'm trying to duplicate a loaded swf but i don't seem to be able to create a duplicate

 

i'm using the following code:

public function getAssetById(assetId:String):DisplayObject
{
var asset:DisplayObject;

if (!_assetCache[assetId])
{
	_assetCache[assetId] = LoaderMax.getContent(assetId).rawContent;
}

asset = _assetCache[assetId];

// duplicate bitmap
if (asset is Bitmap)
{
	var bmd:BitmapData = new BitmapData(asset.width, asset.height, true, 0);
	return new Bitmap(bmd, "auto", true);
}
// otherwise return swf
return SpriteUtils.duplicateDisplayObject(asset);
}

and this is SpriteUtils.duplicateDisplayObject(asset) (taken from http://www.kirupa.com/forum/showthread.php?223798-ActionScript-3-Tip-of-the-Day&p=1939827&viewfull=1#post1939827)

static public function duplicateDisplayObject(target:DisplayObject, autoAdd:Boolean = false):DisplayObject
{
// create duplicate
var targetClass:Class = Object(target).constructor;
var duplicate:DisplayObject = new targetClass();

// duplicate properties
duplicate.transform = target.transform;
duplicate.filters = target.filters;
duplicate.cacheAsBitmap = target.cacheAsBitmap;
duplicate.opaqueBackground = target.opaqueBackground;
if (target.scale9Grid)
{
	var rect:Rectangle = target.scale9Grid;
	// WAS Flash 9 bug where returned scale9Grid is 20x larger than assigned
	// rect.x /= 20, rect.y /= 20, rect.width /= 20, rect.height /= 20;
	duplicate.scale9Grid = rect;
}

// add to target parent's display list
// if autoAdd was provided as true
if (autoAdd && target.parent)
{
	target.parent.addChild(duplicate);
}
return duplicate;
}

 

if i simply return the asset from _assetCache (which is a dictionary) without duplicating it, it works and traces as a MovieClip but when i try to duplicate it, even though the traces tell me that the duplicate is a movieclip. Note the clip being loaded is a simple vector graphic on the stage of the root of the timeline

 

thanks in advance

obie

Link to post
Share on other sites

I don't have a definitive answer for you but did you try using the content instead of rawContent?

 

_assetCache[assetId] = LoaderMax.getContent(assetId)

 

///

 

if you temporarily remove LoaderMax from the mix and just use a regular AS3 loader will it work?

This will at least help to see if it is a LoaderMax issue or something with the duplicate script.

 

///

Link to post
Share on other sites

hey carl

 

i did try just the content but it can't be cast as a DisplayObject in the duplicateSprite method

 

i'll test the duplicateSprite method with a separate class to make sure that it's all working

 

best

a

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    No registered users viewing this page.

×