0

I have simple code as3 with sharedobject. In this flash, I want to save name and score that writed by user. New name and score will show in the top, and the rest will follow under the new name and score. But I don't sure how to make it. I have dynamic text in next frame that will display the name and score.

stop();
var savedstuff:SharedObject = SharedObject.getLocal("myStuff");

btnSave.addEventListener(MouseEvent.CLICK, SaveData);
btnLoad.addEventListener(MouseEvent.CLICK, LoadData);
var cek:int = 0;

function SaveData(MouseEvent){
    if (cek==0){
         savedstuff.data.username = nameField.text
         savedstuff.data.score = scoreField.text
         savedstuff.data.username2 = "-";
         savedstuff.data.score2="-";
         cek=1;
    }
    else{
         savedstuff.data.username2 = nameField.text
         savedstuff.data.score2 = scoreField.text 
    }
    savedstuff.flush(); // saves data on hard drive
}
function LoadData(MouseEvent){
    nextFrame();
}

Hopeless with this code, can anybody help me?

ayu
  • 23
  • 4
  • You can store your users data as an array : `[ { 'username': 'user 1', 'score': 123 }, { 'username': 'user 2', 'score': 456 }, ... ]` ... – akmozo Jan 07 '16 at 04:09
  • But I don't know how to read data in sharedobject with array? – ayu Jan 07 '16 at 05:28
  • It's exactly the same as you do usually with an array : `var a:Array = shared_object.data.users; /* users here is an array */` ... – akmozo Jan 07 '16 at 05:42

0 Answers0