AIR 응용 프로그램을 만들고 있는데 한 번만 함수를 실행할 수 있는지 알고 싶습니다.AS3 함수를 한 번만 실행하십시오.
사용자가 기기를 재부팅하고 앱을 실행하면 기능이 다시 트리거되지 않습니다.
답장을 보내 주셔서 감사합니다.
AIR 응용 프로그램을 만들고 있는데 한 번만 함수를 실행할 수 있는지 알고 싶습니다.AS3 함수를 한 번만 실행하십시오.
사용자가 기기를 재부팅하고 앱을 실행하면 기능이 다시 트리거되지 않습니다.
답장을 보내 주셔서 감사합니다.
어도비 AIR를 사용하고 있으므로 몇 가지 옵션이 있습니다.
저장 데이터가있는 파일을 작성하십시오.
AIR을 사용하면 데이터 파일을 사용자 컴퓨터에 쓸 수 있습니다. 이것은 SharedObject의 것보다 영구적입니다. 여러 가지 이유로 인해 장기간 지속되거나 지속될 수 없습니다.
복잡한 객체를 쉽게 검색 할 수 있도록 전체 클래스를 실제로 직렬화 할 수 있습니다.
package
{
import flash.filesystem.File;
import flash.filesystem.FileMode;
import flash.filesystem.FileStream;
import flash.utils.ByteArray;
import flash.utils.Dictionary;
import flash.net.registerClassAlias;
public class SaveData
{
//a list of any vars you want to save.
public var firstRun:Boolean = true;
public var someVar:int = 1;
public var anotherVar:Dictionary;
//the file for the user save data
public static function getFile():File {
return File.applicationStorageDirectory.resolvePath("saveFile.data");
}
public static function loadFile():SaveData {
registerClassAlias("flash.utils.Dictionary", Dictionary); //you need to register any non-native classes you want to save
registerClassAlias("saveData", SaveData);
var data:SaveData
//check for a default save file in the application directory (optional, but sometimes it's nice to bundle a default with your application before the user saves their own data
var f:File = new File("app:/saveFile.data");
if(f.exists){
data = loadFromFile(f);
}else {
trace("Default File Doesn't Exist");
}
//check the user storage directory for a save file, and see if it's newer than the one in the application directory
var userFile:File = getFile();
if (userFile.exists) {
if (f.exists && f.modificationDate.time < userFile.modificationDate.time) {
trace("Local File is newer, load it");
data = loadFromFile(userFile);
}else {
trace("Default File is newer");
}
}else {
trace("Save File DOESN'T EXIST YET");
}
if (!data) {
//data didn't load, let's create a new save file
data = new SaveData();
saveToFile(data);
}
saveData = data; //assing to main static accessible var
return data;
}
private static function loadFromFile(f:File):SaveData {
var d:SaveData;
try{
var stream:FileStream = new FileStream();
stream.open(f, FileMode.READ);
d = stream.readObject() as SaveData;
stream.close();
trace("DATA LOADED: " + f.nativePath);
return d;
}catch (err:Error) {
trace("Error Loading Save Data: " + f.nativePath);
}
return null;
}
public static function saveToFile(saveData:SaveData):void {
var fileStream:FileStream = new FileStream();
fileStream.open(getFile(), FileMode.WRITE);
fileStream.writeObject(saveData);
fileStream.close();
}
}
}
이 그 다음을 사용 : var saveData:SaveData = SaveData.loadFile();
if(saveData.firstRun){
//do you first run code
//now set first run to false
saveData.firstRun = false;
SaveData.saveFile(saveData);
}
가있는 SharedObject를 사용하여 여기에
은 관리자가 (기본 설정 또는 기타 저장 게임) 파일을 저장하는 클래스의 예이다. 이이 문제를 다루는 또 다른 대답은 있지만 예를 지정하지 이후 나는 하나주지 :var mySO:SharedObject = SharedObject.getLocal("yourAppNameHere");
if(mySO.data.hasHadFirstRun){
//the cookie exists
}else{
//the cookie hasn't indicated there has been a first run yet, so do whatever you need to do
//some code
mySO.data.hasHadFirstRun = true; //now that you've done whatever on the first run, let's save the cookie
mySO.data.flush(); //save (though it will save automatically I believe when you close the application
}
사용 SQLite는.
AIR에서는 SQLite 데이터베이스를 만들고 읽을 수 있습니다. 응용 프로그램에서 테이블 구조로 사는 것이 타당한 다른 데이터를 저장해야하는 경우 사용자 환경 설정 및 사물을 저장하기위한 테이블을 추가하는 것이 좋습니다 첫 번째 실행 플래그와 같습니다. 데이터베이스를 다른 용도로 사용하지 않는다면 과도하게 죽일 것입니다.
여기 AIR에서 SQLite는 대한보다 자세한 정보 http://help.adobe.com/en_US/as3/dev/WS5b3ccc516d4fbf351e63e3d118666ade46-7d49.html
당신에게 예를 주셔서 대단히 감사합니다! – user3094896