-1
\$\begingroup\$

This question is an exact duplicate of:

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);
}
\$\endgroup\$

marked as duplicate by Jesse Dorsey Apr 29 '17 at 23:01

This question was marked as an exact duplicate of an existing question.

0
\$\begingroup\$

You can't

Sorry. But SharedObjects can't actually serialize movieclips.

Quoting myself from 2010 (I was quite the AS guru back then):

You need to individually save each variable the MC has (x and y position, etc) so you load them back in.

\$\endgroup\$

Not the answer you're looking for? Browse other questions tagged or ask your own question.