coding and other fun

Flex, Java …and all the rest - by Bernhard Hirschmann

Entries Comments



Cloning an object in ActionScript

15 April, 2008 (10:19) | ActionScript | By: admin

If you too asked yourself “how can I clone an object in AS?” - fortunately it is as simple as in other programming languages. Again, the challenge is to find the right utility class for it.

Just use ObjectUtil.copy:

var clone:Object = ObjectUtil.copy(originalObject) as Object;

Thats about it.

But remember Adobes documentation about this function: “This method is designed for copying data objects, such as elements of a collection. It is not intended for copying a UIComponent object, such as a TextInput control. If you want to create copies of specific UIComponent objects, you can create a subclass of the component and implement a clone() method, or other method to perform the copy.”

Write a comment