AS3 Duplicate Object

This is something I found on Darron Schall’s site. In Flex they have a utility function built in for duplicating objects, but the same functionality doesn’t exist in side of Flash, or does it? While we don’t have a simple function call available to us, the Flex function uses some built in methods of the byteArray class to accomplish this, and it is really simple. This is what it looks like:

function copy(value:Object):Object {
    var buffer:ByteArray = new ByteArray();
    buffer.position = 0;
    var result:Object = buffer.readObject();
    return result;

Very handy!


AS3, Flash

You can contact me on Twitter.


Browse All >