views:

59

answers:

2

Hi all, I have an object and a temp object now if i do tempObj = obj

and change stuff in tempObj they changes have an effect on obj is there a way i can stop it from doing this? Regards Mark

+2  A: 

Hi

This is a standard behavior in many languages. When you do tempObj = obj you are NOT creating a duplicate object. You are creating another reference to the same object.

I don't think you can change this behavior, and certainly I don't think you should :)

What you need is creating another object, a duplicate of the original object. You can implement a function to do that. Maybe this can help http://blog.comtaste.com/2007/10/improving_object_copy.html

Good luck!

Rafa G. Argente
Ok i will have a look into this cheers. I will let you now if it does what i need
markblue777
with a bit more digging around but from your direction i got what i wanted cheers for the help fella
markblue777
glad it helped!
Rafa G. Argente
+1  A: 

What you are doing is making a reference to the original object not a copy of the original. You should create a deep copy of your object. It seems that someone already wrote the steps to do so...

http://www.as3dp.com/2008/09/23/actionscript-30-clone-a-prelude-to-the-prototype-design-pattern/

Hope this helps

AndrewB