1

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

Helen
  • 87,344
  • 17
  • 243
  • 314
markblue777
  • 829
  • 3
  • 13
  • 28

2 Answers2

2

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!

rgargente
  • 1,821
  • 2
  • 19
  • 30
1

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
  • 962
  • 1
  • 10
  • 18