Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><strong>Short answer:</strong></p> <p>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.)</p> <p><strong>Long answer:</strong> </p> <p>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.</p> <p>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.</p> <p>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. </p> <p>Either way, at the end of the day the problem is architectural, so the solution will need to be as well.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload