I'm making a city builder game, where players can build their town using different constructions. A player has the possibility to save his city. In the main menu, a player can choose to see different cities of others players.
When a player want to save his city, a button is clicked and an array that contains all the display objects (so all the buildings) must be saved in a sharedObject. I've tried this solution, but it doesn't seem to work. I don't know how to load this type of array, because I've been told that I can store only plain data types in a shared object.
this is the sample code:
var SO:SharedObject=SharedObject.getLocal("myFile", "/");
var arr:Array=new Array();
var counter:Number=-1;
addBtn.addEventListener(MouseEvent.CLICK, addObjects);
saveBtn.addEventListener(MouseEvent.CLICK, saveObjects);
loadBtn.addEventListener(MouseEvent.CLICK, loadObjects);
function addObjects(event:Event) {
counter++;
var circle:circleClip=new circleClip();
arr.push(circle);
trace("current object: "+arr[counter]);
}
function saveObjects(event:Event) {
SO.data.arrSaved=arr;
SO.flush();
trace("objects saved: "+SO.data.arrSaved);
}
function loadObjects(event:Event) {
var arrLoaded:Array=new Array();
arrLoaded=SO.data.arrSaved;
trace("objects loaded: "+arrLoaded);
}