duplicating an object doesn't seems to work if the original object contains an array. Is there a way around this? Here's my code:
Any ideas?Code:var originalObj:Object = {people: [{nm: "max"}], age:41, city:"Los Angeles"} var newObj:Object = new Object() // I copy all properties of the original object into the newObj for (var a:String in originalObj) newObj[a] = originalObj[a] // traces out as expected trace("name and ages are the same: "+originalObj.people[0].nm+" "+newObj.people[0].nm+" "+originalObj.age+" "+newObj.age) // I make a change in the array property of the newObj newObj.people[0].nm = "Kadin" // I make a change to the number property of the newObj newObj.age = 4 // the number property works as expected but the change to the array is applied to both the originalObj & newObj objects trace("names are same but ages are not "+originalObj.people[0].nm+" "+newObj.people[0].nm+" "+originalObj.age+" "+newObj.age)




Reply With Quote
