로컬에 데이터 저장

1820 단어 데이터
var topNum:int;

var topList:Array;



// 

function submitScore():void

{

	if (_txt.text != "")

	{

		readScore();

		var newRecord:Object = {player:_txt.text,score:Number(_txt1.text)};

		topList.push(newRecord);

		topList.sortOn("score",Array.NUMERIC|Array.DESCENDING);

		saveScore();

	}

}

// 

function saveScore():void

{

	var so:SharedObject = SharedObject.getLocal("heroList");

	var str:String = "";

	var count:int = 0;

	while (topList.length!=0&&count<topNum)

	{

		var temp:Object = topList.shift();

		str +=  temp.player + ":" + temp.score;

		count++;

		if (topList.length != 0 && count < topNum)

		{

			str +=  ",";

		}

	}

	so.data.topList = str;

	so.flush();

}

// 

function readScore():void

{

	topList = new Array  ;

	var so:SharedObject = SharedObject.getLocal("heroList");

	var str:String;

	if (so.data.topList != null)

	{

		str = String(so.data.topList);

		trace(str);

	}

	var topScore:Array;

	if (str != null)

	{

		topScore = str.split(",");

		for (var i:int=0; i<topScore.length; i++)

		{

			var singleRecord:Array;

			singleRecord = String(topScore[i]).split(":");

			var newRecord:Object = {player:String(singleRecord[0]),score:Number(singleRecord[1])};

			topList.push(newRecord);

		}

	}

}



// 

function displayScore():void

{

	readScore();

	for (var i:int=0; i<topList.length; i++)

	{

		MedalList.appendText(i+1+"."+topList[i].player.toString()+"
"+"
"); MedalList1.appendText("-----"+topList[i].score.toString()+"
"+"
"); } } // ; function eliminate():void { var so:SharedObject = SharedObject.getLocal("heroList"); so.clear(); }

좋은 웹페이지 즐겨찾기