Groups | Blog | Home
all groups > flash actionscript > november 2004 >

flash actionscript : Copy Object contents to LoadVars


Philip Bulley
11/24/2004 7:51:38 PM
Hi,

Anyone know of an easy way to copy the vars inside an object created with "foo
= new Object();" into a LoadVars object.

ie:

foo = new Object();
myVars = new LoadVars();

i want to copy:
foo.hello
into myVars, to create:
myVars.hello

BUT: I don't want to alter the LoadVars object type! Thus, "myVars = foo" will
not work.

Any ideas appreciated!

Thanks,
Phil
NSurveyor
11/24/2004 7:55:36 PM
Philip Bulley
11/24/2004 8:37:22 PM
Thanks NSurveyor.

So each var needs to be copied one by one?

You see, I have x amount of vars in my Object with different names. Have you
ever come accross a clever little function which will copy the vars over, with
the same var names and values?

Or possibly, make a duplicate of the populated Object, and then convert the
duplicate to a LoadVars object?

Tnx

NSurveyor
11/24/2004 8:51:44 PM
I have never come across it, but I did manage to figure it out. Use this bit o' code:
for (name in foo) {
myVars[name] = foo[name];
}
Philip Bulley
11/25/2004 2:39:31 PM
Thank you NSurveyor.
Works a treat!

Many thanks,
AddThis Social Bookmark Button