Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6179603
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T00:41:53+00:00 2026-05-24T00:41:53+00:00

i’m trying to duplicate a swf loaded using greensocks LoaderMax but i don’t seem

  • 0

i’m trying to duplicate a swf loaded using greensocks LoaderMax but i don’t seem to be able to

i’m using the following code:

private var _assetCache : Dictionary;

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 
    return SpriteUtils.duplicateDisplayObject(asset);
    //return asset; // if previous line is commented out, this works well but there will be only a single copy of the loaded swf, kinda negating the use of a cache
}

and this is SpriteUtils.duplicateDisplayObject(asset) (taken from this

static public function duplicateDisplayObject(target:DisplayObject, autoAdd:Boolean = false):DisplayObject
{
    // create duplicate
    var targetClass:Class = Object(target).constructor;
    var duplicate:DisplayObject = new targetClass();
    trace(duplicate, duplicate.height); // traces [MovieClip, 0]
    // 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

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T00:41:53+00:00Added an answer on May 24, 2026 at 12:41 am

    I don’t think simply calling the constructor will work.

    Try doing this (I’ve assumed certain previous knowledge since you’re able to get rawContent above):

    1) Load the data in using DataLoader in binary mode…. in the context of LoaderMax it would be like: swfLoader = new LoaderMax({name: “swfLoader”, onProgress:swfProgressHandler, onChildComplete: swfLoaded, auditSize:false, maxConnections: 2}); swfLoader.append(new DataLoader(url, {format: ‘binary’})); (the main point is to use DataLoader with format=’binary’)

    2) Upon complete, store the ByteArray which this returns into your dictionary. The first part of your above code will basically be unchanged, though the bytearray might be in content rather than rawContent

    3) Whenever you need a duplicate copy, use Loader.loadBytes() on the ByteArray. i.e. var ldr:Loader = new Loader(); ldr.contentLoaderInfo.addEventListener(Event.COMPLETE, swfReallyLoaded); ldr.loadBytes(_assetCache[assetId]);

    As with all loading, you might need to set a LoaderContext, and if in AIR- allowLoadBytesCodeExecution = true; allowCodeImport = true;

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.