As3 Copy Object

sometimes we need to clone an object. but if displayObject has multiple children and uses a function like this:

function clone(source:*):*
{
    var b:ByteArray = new ByteArray();
    b.writeObject(source);
    b.position = 0;
    return(b.readObject());
}

but the result has no children ..... so what should I do?

+3
source share
2 answers

I didn't need to program the clone method yet, but I found a way that could do the trick. Iterating over all the variables (in the xml representation), you can copy them to a new instance of your class.

you can find the method I'm talking about at this link: http://www.learnosity.com/techblog/index.cfm/2008/2/6/AS3--Looping-over-properties-of-a-class

Let me know if this works, I'm curious myself :)

+1
source

, ActionScript .

, / ByteArray , .. . ByteArray (Number, int, String ..)

, - clone() .

+3

All Articles