views:

259

answers:

3

Imagine I have an object called "image", now I want to create multiply copies of this image to display it multiple times and with different properties. When I do image2 = image;, only the reference is copied and I thus still change the properties of the first object.

So, how to return a copy of an object instead of a reference in actionscript 3?

+1  A: 

Have a look at this post.

Vinay Sajip
+1  A: 

Create a clone method in the class. This post mentions at the end how to do this for BitmapData, which you'll probably need for an image.

igkuk7
+1  A: 

For a more generic solution, take a look at this:

http://www.kirupa.com/forum/showpost.php?p=1897368&postcount;=77

Lior Cohen
Nice, any idea how to make it retain class association?
Tom
Looking into this, mate. This is also relevant to the previous asset loading class question I've answered for you a couple of weeks ago. Will update this post when I'm done playing. It should be possible, tho.
Lior Cohen
Sweet, thanks a lot for the effort.
Tom