Using the new ByteArray (flash.utils.ByteArray) class in ActionScript 3, you can now easily create deep object copies. By deep, I mean being able to create copies not of just a single object and all its references, but also all the objects it references. This means if you use this method to copy an array which references an object, that object will also be copied as part of the copy procedure. Such a copy (clone) method would look like the following:
var copier:ByteArray = new ByteArray();
copier.writeObject(source);
copier.position = 0;
return(copier.readObject());
}
Note: you may need to import flash.utils.ByteArray;
To use this function simply say:
Though this will make a deep copy of your objects, be aware that it does not retain class association. So, if you try to copy a MyClass instance, the copy will no longer be recognized as being of MyClass. This method is best used with generic objects.
You might also like
| Tricks and Experiments , AS3 Tips As you read each of the following descriptions, consider opening Flash, pasting the code into timeline script and... | Using Caurina Tweener Class AS3 I enjoy to use in my flash projects the caurina tweener class, because it’s simple, elegant and flexible. You... | Using other types within ActionScript packages I was doing something, I forget what it was now, but it got me curious about functions defined in some of the... | New templates Oval light added to flash banner online New template Oval Light Flash online banner added, you can now easily mold to your banner Select. An... |







