I'm saving some values in the shared objects. Data are being saved and retrieved perfectly (i see the visual part of the app changes along with variable altering). After every change to any variable I use so.data.flush() to save it to the object instantly.
Problem starts when i close my application (using the red phone symbol) and restart it. Variables are being reset to initial state.
Should i use a designated "quit" button assigned to one of the softkeys? I would like to avoid that, since the users will definitely avoid that one too
I just don't get where have i gone wrong in that one.
Here's how i initialize SO:
And a sample save to SO:Code://initiating shared objects: so = SharedObject.getLocal("variables"); var now = new Date(); if (so.data.so_check!=1){ so.data.Con = 5; so.data.Str = 1; so.data.Int = 1; so.data.Fat = 0; so.data.Hap = 0; so.data.Rom = 0; so.data.Hair = 2; so.data.Money = 200; so.data.timestamp = (now.getTime())/86400000; //USE actions variables so.data.useGym = 0; so.data.useHealth = 0; so.data.useRead = 0; so.data.useJunk = 0; so.data.useSex = 0; //married? so.data.married = false; so.data.so_check = 1; so.data.flush(); } //init handler - assigns variables form shared object to global variables soInitHandler = function(so:SharedObject){ if (so.getSize() > 0){ //all the variables get here Con = so.data.Con; Str = so.data.Str; Int = so.data.Int; timestamp = so.data.timestamp; money = so.data.money; //Use acations variables useGym = so.data.useGym; useHealth = so.data.useHealth; useRead = so.data.useRead; useJunk = so.data.useJunk; so.data.so_check = 1; } } SharedObject.addListener("variables" , soInitHandler);
Just checked the app on Sony Ericsson (which runs flash lite 1.1) and it saved the SO. Now i'm dazzled. Is it just Nokias that don't allow to save data on the phone?!?Code://sample save to shared object function: function goToGym(){ //Altering basic attributes so.data.Str = so.data.Str + 0.1; so.data.Con = so.data.Con + 0.1; so.data.Int = so.data.Int - 0.1; so.data.money = so.data.money - 20 ; //Reseting the Use vars for other actions so.data.useHealth = 0; so.data.useRead = 0; so.data.useJunk = 0; so.data.useGym = so.data.useGym + 1; so.data.flush(); Key.removeListener(_root.myListener); gotoAndStop(2); }





