Skip to main content
Post Closed as "Duplicate" by Jesse Dorsey
rejecting edit for attempt to reply; fixing punctuation and code format
Source Link
Gnemlock
  • 5.3k
  • 5
  • 30
  • 60

How todo I load an array of display objects with shared objects using action script 3.0?

I'm making a city builder game, where players can build their town using different constructions. aA player has the possibility to save his city.In 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 that contains all the display objects, so (so all the buildings) mustsmust be saved in a sharedObjectsharedObject. I've tried this solution, but it doesn't seem to work. Here I put a sample code where I explain my problem: I don't know how to load this type of array, because I've been saidtold that I can store only plain data typetypes 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 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) {

}

function saveObjects(event:Event) {

    SO.data.arrSaved=arr;
 
    SO.flush();
 
    trace("objects saved: "+SO.data.arrSaved);

}

function loadObjects(event:Event) {

}

function loadObjects(event:Event) {

    var arrLoaded:Array=new Array();
 
    arrLoaded=SO.data.arrSaved;
 
    trace("objects loaded: "+arrLoaded);
}

}

How to load an array of display objects with shared objects using action script 3.0

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) musts be saved in a sharedObject. I've tried this solution but it doesn't seem to work. Here I put a sample code where I explain my problem: I don't know how to load this type of array, because I've been said that I can store only plain data type 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);

}

How do I load an array of display objects with shared objects using action script 3.0?

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);
}
Source Link

How to load an array of display objects with shared objects using action script 3.0

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) musts be saved in a sharedObject. I've tried this solution but it doesn't seem to work. Here I put a sample code where I explain my problem: I don't know how to load this type of array, because I've been said that I can store only plain data type 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);

}