I’m trying to write a save function for my project using a SharedObject. However, I’ve noticed that when you save Array values to one, the values only stay in there when loading the game from the same instance I saved it in. Here’s my code:
I’m saving an Array of a user-defined class “Job”:
public function saveGame(v_saveGameData:SharedObject):Boolean{
v_saveGameData.data.jobHistory = Main_Game(parent).jobHistory as Array;
...
}
Now I load the data:
public function loadGame(v_loadGameData:SharedObject):Boolean{
Main_Game(parent).jobHistory = v_loadGameData.data.jobHistory as Array;
trace("JobHistory: " + Main_Game(parent).jobHistory);
...
}
If I save my game, go to the main menu, and load my game, the trace reads:
“JobHistory: [object Job]”
and the game properly loads.
However, if I close my game, reopen the file, then load, the trace reads:
“JobHistory: [object Object]”
and I get an error about “not being able to convert type Object to Job”
Seems to me, the problem is that when I close down the game, my save data forgets the custom class type stored in the array. Does anyone know how to fix this?