나는 안드로이드에 대한 약간의 보드 게임을 시작했고 점수를 영구적으로 저장하는 방법을 연구 해 왔습니다. 사용자가 "AI"와의 게임을 할 때마다 포인트를 얻습니다 (특수 폰 및 보드 게임을 잠금 해제하는 데 사용할 수 있음). SharedObject를 사용하려고 시도하지만 사용자가 게임 데이터를 삭제하면 지울 수 있습니다. 그래서 나는 Filestream과 함께 갔다. 나는 그것에 관해 약간의 지위를 읽었고, 내가 이해했다라고 생각했다. 그러나 그것이 나를 위해 일하지 않고있는 이래로, 나는 내가하지 않았다고 생각한다 :). Filestream (AS3 - Air for Android)를 사용하는 점수
var wonGames:int; //variable I want to save
function writeObject():void { //First function to create/write in the file
var score1:Object = new Object();
score1.value = wonGames; //value of object = variable value
trace(score1.value);
var file:File = File.applicationStorageDirectory.resolvePath("score1.file");
var fileStream:FileStream = new FileStream();
fileStream.open(file, FileMode.WRITE);
fileStream.writeObject(score1);
fileStream.close();
};
function readObject():void { //second function to read the file and modify the variable.
var file:File = File.applicationStorageDirectory.resolvePath("score1.file");
if (!file.exists) {
return;
}
var fileStream:FileStream = new FileStream();
fileStream.open(file, FileMode.READ);
var score1:Object = fileStream.readObject();
wonGames=score1.value;//update the variable
fileStream.close();
};
btn26.addEventListener(MouseEvent.CLICK, fnBtn26);
function fnBtn26(e: Event): void { //third function, where the winning happens
if (winP1.currentFrame==1){ //game won
winP1.nextFrame(); //victory screen
readObject(); //get old value for score 1
wonGames=wonGames+1; //update it
trace("WonGames= "+ wonGames);
writeObject(); //write it in file
}
};
wonGames
귀하의 코드가 잘 보이는 업데이트합니다. 귀하의 질문에 언급 된 코드와 APK를 생성하고 그것을 공유 할 수 있습니다, 문제는 귀하의 안드로이드 장치와 코드에서 오는 것일 수 있습니다? – akmozo
답변 해 주셔서 감사합니다. https://www.dropbox.com/s/79k7umu5bjufxu4/Untitled-1.apk?dl=0. 다른 장치를 사용해보고 보겠습니다. :) – Jeryl
문제없이 나를 위해 일하고있어, 여기 [http://i58.tinypic.com/2zxnmu0.png]보세요. Android 4.1.1 및 AIR 15가있는 태블릿을 사용했습니다. – akmozo