文件流 (AS3) 中的多个变量
Multiple variables in Filestream (AS3)
我正在使用 Filestream 保存 android 游戏的分数。最近,我决定添加额外的级别。对于这些级别,我需要跟踪多种类型的分数。这是我的一个变量代码:
function writePion(): void { //First function to create/write in the file
var pion: Object = new Object();
pion.value = numeroPion; //value of object = variable value
trace("Pion (writeObject value)= " + pion.value);
var file2: File = File.applicationStorageDirectory.resolvePath("pion.menes");
var fileStream2: FileStream = new FileStream();
fileStream2.open(file2, FileMode.WRITE);
fileStream2.writeObject(pion);
fileStream2.close();
};
function readPion(): void { //second function to read the file and modify the variable.
var file2: File = File.applicationStorageDirectory.resolvePath("pion.menes");
if (!file2.exists) {
return;
}
var fileStream2: FileStream = new FileStream();
fileStream2.open(file2, FileMode.READ);
var pion: Object = fileStream2.readObject();
numeroPion = pion.value; //update the variable
trace("pion (readObject value)= " + numeroPion)
fileStream2.close();
};
我想知道我是否必须为每种类型的乐谱创建其中一个函数,或者是否有办法调整它以保存(大约 10 个)新变量?
谢谢 :)
杰瑞尔.
如果 filestream.writeObject() 可以写入任何对象,您可以使用以下语法在其中定义和分配任意数量的字段:
var pion:Object = { value: numeroPion, value2: numeroPion2, some_other_value: numeroPionSomeOther }; // and so on
您可以阅读这些值
numeroPion = pion.value;
numeroPion2 = pion.value2;
// ... and so on
我正在使用 Filestream 保存 android 游戏的分数。最近,我决定添加额外的级别。对于这些级别,我需要跟踪多种类型的分数。这是我的一个变量代码:
function writePion(): void { //First function to create/write in the file
var pion: Object = new Object();
pion.value = numeroPion; //value of object = variable value
trace("Pion (writeObject value)= " + pion.value);
var file2: File = File.applicationStorageDirectory.resolvePath("pion.menes");
var fileStream2: FileStream = new FileStream();
fileStream2.open(file2, FileMode.WRITE);
fileStream2.writeObject(pion);
fileStream2.close();
};
function readPion(): void { //second function to read the file and modify the variable.
var file2: File = File.applicationStorageDirectory.resolvePath("pion.menes");
if (!file2.exists) {
return;
}
var fileStream2: FileStream = new FileStream();
fileStream2.open(file2, FileMode.READ);
var pion: Object = fileStream2.readObject();
numeroPion = pion.value; //update the variable
trace("pion (readObject value)= " + numeroPion)
fileStream2.close();
};
我想知道我是否必须为每种类型的乐谱创建其中一个函数,或者是否有办法调整它以保存(大约 10 个)新变量? 谢谢 :) 杰瑞尔.
如果 filestream.writeObject() 可以写入任何对象,您可以使用以下语法在其中定义和分配任意数量的字段:
var pion:Object = { value: numeroPion, value2: numeroPion2, some_other_value: numeroPionSomeOther }; // and so on
您可以阅读这些值
numeroPion = pion.value;
numeroPion2 = pion.value2;
// ... and so on