Skip to main content
November 15, 2006
Question

Strange Problem in Object !

  • November 15, 2006
  • 3 replies
  • 256 views
Hi Macromedia Experts,

I having a strange problem with the objects...
I found the solution anyhow.
But, I want to know why this happen..
See the code..
This topic has been closed for replies.

3 replies

Inspiring
November 15, 2006
Not sure what the real issue is. But if you want to "copy" the object's
properties/values you need to perform a deep copy.

There's this method :
http://theolagendijk.wordpress.com/2006/09/04/actionscript-object-duplication/

or you can simply create a recursive function using the same code:

function copyObject(source:Object):Object{
var result:Object = new Object();
for(var i in source){
if (typeof(source ) == "object"){
result
= copyObject(source )
}
else{
result
= source ;
}
}
return result;
}


November 15, 2006
do you have any other solutions for this ?????
Inspiring
November 15, 2006
No strange behavior here.

// create an object and assign it to the variable myObj1
var myObj1:Object = new Object();
myObj1.name = "Arun";
myObj1.age = "25";

// create an object and assign it to the variable myObj2
var myObj2:Object = new Object();

// abandon second object and assign to myObj2 the same object
// that is assigned to myObj1 -- now both variables point to
// the same object

myObj2 = myObj1;

// change the name property of both myObj1 and myObj2
myObj2.name = "Macromedia";

trace("First Object :"+myObj1.name+" <---------------> Second Object
:"+myObj2.name);