Dwedit's Board

Enjoy the board

You are not logged in.

Announcement

Welcome, fellow visitors from other websites!
Whenever you download a file, I'd appreciate it if you posted a nice "Thank You" message, then tell me which site you came from. Thanks.
- Dwedit

#1 2009-03-28 8:50:18 am

Dwedit
Princess Lapis of Sorcerland (Administrator)
From: Chicago
Registered: 2004-12-12
Posts: 942
Website

Flash Shared Objects 101

Flash Shared Objects 101:

When making a flash save game, NEVER do this:
mySO = SharedObject.getLocal('Foo');
mySO.data.some_array=some_array;

If you do, the shared object contains a REFERENCE to the array, and the shared object will change as the game changes the array.  So you go save your game, run the game, then some stuff that happened in your game now sticks in the savefile even though you didn't save again.

Instead do this:

	function copy_object(src)
	{
		if (typeof(src)!="object")
		{
			return src;
		}
		var dest=new src.__proto__.constructor();
		for (var v in src)
		{
			dest[v]=copy_object(src[v]);
		}
		return dest;
	}

then use it like this:
mySO = SharedObject.getLocal('Foo');
mySO.data.some_array=copy_object(some_array);

No matter what type you are using, it will save it correctly.

This is for Ationscript 1.x and 2.x, not sure about behavior for AS3.


"We are merely sprites that dance at the beck and call of our button pressing overlord."

Offline

Quick reply

Write your message and submit

Board footer

Powered by FluxBB