我在Air for Android中创建了一个带有高分表的游戏,但我需要将分数保存到手机上。到目前为止,我在模拟器中有工作记分板。我的代码如下:
import fl.data.DataProvider;
var scoreArray: Array = new Array();
dg_score.addColumn("Name");
dg_score.addColumn("Score");
tf_name.text = "Enter name here";
function addScore(evt:MouseEvent)
{
var scoreObj:Object = new Object();
scoreObj["Name"] = tf_name.text;
scoreObj["Score"] = counter.text;
//each time object is added, it is pushed to end of array
scoreArray.push (scoreObj);
//sorted by the score column, in descending order
scoreArray.sortOn("Score", Array.NUMERIC | Array.DESCENDING);
dg_score.dataProvider = new DataProvider(scoreArray);
}
有谁知道我会怎么做?谢谢
答案 0 :(得分:0)
您可以使用SharedObject课程将数据保存到手机
var mySharedObject:SharedObject = SharedObject.getLocal("myScoresObject");
mySharedObject.data.name = name;
mySharedObject.data.score = score;
mySharedObject.flush();
完成此操作后,SharedObject.getLocal("myScoresObject");
将返回已保存的分数。