In ActionScript we cannot pass objects by value. It always passes objects by reference. If you need to create a perfect copy of an object you can make use of the following code. I have modified Flash Guru’s clone with support for Array Objects
[UPDATE] included the ActionScript 3 version as well 🙂 It became lot more simpler with the regular expressions
/*
************************************************************
Developed by R.Arul Kumaran [[email protected]]
for more code keep visiting [www.luracast.com/all/blog]
************************************************************
*/
/*
Object.Clone creates a perfect copy of an object
Modified from FlashGuru's version to support Arrays
*/
/*
Coming Soon...
/*
/*
/*
************************************************************
Developed by R.Arul Kumaran [[email protected]]
for more code keep visiting [www.luracast.com/all/blog]
************************************************************
*/
/*
Object.Clone creates a perfect copy of an object
Modified from FlashGuru's version to support Arrays
*/
Object.prototype.clone = function() {
if (this instanceof Array) {
var to = [];
for (var i = 0; i