xml - AS3 Append data to local file -
i have as3 game played on local desktops (not on network) , need save players details after every game. have tried few methods (filestream, sharedobject, xml) far none have worked. details saved variables player_name , player_score. need these added existing file, don't have sorted or filtered.
for case use simple localshardobject. hope, you'll understand code. otherways, please ask. greetings andré
import flash.events.netstatusevent; import flash.net.sharedobject; var soname:string="yourso" function writescore(playername:string, playerscore:number):void { var so:sharedobject = sharedobject.getlocal(soname); // write new object nemed playername in so.data[playername]= {name:playername, playerscore:playerscore}; // add successlistener so.addeventlistener(netstatusevent.net_status, onflushstatus); // , flush so.flush(); } function readso():object { var so:sharedobject; = sharedobject.getlocal(soname); //if no lso found if (so.size === 0 || so.data.results === null) { _results = []; trace("lso not found"); return; } //for 'playername' can choose name want , add stuff object // object var playername:string = so.data[playername]name; var playerscore:number = so.data[playername]playerscore; trace(playername, playerscore); } function onflushstatus(event:netstatusevent):void { var so:sharedobject = event.target sharedobject; switch (event.info.code) { case "sharedobject.flush.success": trace("value saved in lso"); break; case "sharedobject.flush.failed": trace( "value not saved in lso"); break; } so.removeeventlistener(netstatusevent.net_status, onflushstatus); } //let' try writescore("andre", 10); readso("andre"); writescore("jaytray", 11); readso("jaytray");
Comments
Post a Comment