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

  • SEARCH
  • Home
  • 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 3224214
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T16:11:49+00:00 2026-05-17T16:11:49+00:00

How to copying display objects (sprites, movieclips etc) while keeping thier content (graphics, added

  • 0

How to copying display objects (sprites, movieclips etc) while keeping thier content (graphics, added display objects etc)in AS3?
The most commonly suggested solution by Kirupa (http://www.kirupa.com/forum/showpost.php?p=1939827&postcount=172) doesn’t seem to copy any graphics or child display objects:

// create a sprite
var s:Sprite = new Sprite();
// add a text field
var tf:TextField = new TextField();
tf.text = "nisse";
s.addChild(tf);
// draw something
s.graphics.lineStyle(1, 0x00FF00);
s.graphics.drawCircle(10, 10, 10);
s.x=100;
// add it to parent
this.addChild(s);       

// create a copy using Kirupas duplicate display object solution    
var sCopy:Sprite = duplicateDisplayObject(s, true) as Sprite;
sCopy.x = 200; 
// confirem that the copy exists:
trace(sCopy);
// add to parent
this.addChild(sCopy); // <- works, but the original textfield and graphics are gone!

Is there a sloution to this? (If not – Why? Isn’t a display object represented by a memory area that should be possible to copy, like any other object?)

  • 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-17T16:11:49+00:00Added an answer on May 17, 2026 at 4:11 pm

    Short answer:

    Graphics are not introspectable at runtime. No matter what Kirupa’s code is doing, it has no way of knowing what shape you drew, and no way of copying or re-drawing it. (The textfield getting left out might be a bug or by design, I have no idea, but there’s no getting around the shape.)

    Long answer:

    A DisplayObject is not just a chunk of memory, like a bitmap or a string. It’s an object, with a great many child properties, many of which are also objects, or functions, or classes, etc. So when you say you want to duplicate one, it’s worth asking what precisely that means. Should child objects, like Arrays for example, be copied by reference or duplicated? If any of the objects hold references to other display objects, besides their list of children, how do you know whether to copy the reference or duplicate the target? If some of the original objects were listening for keyboard events or running timers, would the duplicates work without being registered as well? Et cetera, et cetera.

    All of which is a long-winded way of saying, in OOP languages (like AS3), there’s no universally meaningful way to duplicate objects. Granted, you can recurse through a tree of MovieClips, making new ones and attempting to copy properties from the originals to the duplicates – and that’s what Kirupa’s code is presumably doing. But for anything except trivial content, as you’re finding out, this won’t get you what you want. That’s why there’s no built-in way to do this – because most of the time it wouldn’t do what people hoped.

    Ultimately, the real solution to this kind of problem is to take a careful look at what needs to be accomplished, and figure a way to do it without duplicating objects. If you need only a visual copy of the original, you might consider drawing the original into a bitmap every frame. Or perhaps the best approach is to build a data structure containing all the information relevant to your object, so that you could duplicate the data and initialize an object based on it. Or perhaps you should be creating a pool of objects initially, and maintaining each, so that when you need duplicates later you have them.

    Either way, at the end of the day the problem is architectural, so the solution will need to be as well.

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

Sidebar

Related Questions

Is there any way to prevent users from copying content from website and display
Would it be possible to display different content if someone opened one of my
Copying Zenf Framework everywhere is a nightmare, so I had an idea, thas deployment
Copying a File using a straight-forward approach in Python is typically like this: def
Is copying the .hg directory to another directory the same as cloning in Mercurial
I'm copying a Magento Enterprise 1.11.2.0 core file called Preview.php into the local folder
I'm having trouble copying a file and then verifying the integrity of the file
I am copying code from website matplotlib and pasting into the Vim editor in
I am copying a file to a directory, and then setting an environment variable
I'm copying ListViewItems from one ListView to another, sth. like: foreach (ListViewItem item in

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.