Save & load State AS3 + Adobe Air



如何使用Adobe Air保存和加载?这一直是我想知道的事情。我以前问过这个问题,但我只知道用什么,却不知道怎么用。假设我在第59帧保存状态,我关闭并结束应用程序,然后当我点击加载时,我如何让它回到第59帧?请帮帮我!

1。始终将当前框架写入sharedObject或文件

 ex. onEnterFrame(ev:Event){ //write current frame somewhere }

2。当应用程序启动时,首先检查文件或共享对象的最后保存帧数。如果没有找到,默认是第一帧,否则gotoAndPlay(frame_saved);

对不起,但是在这个论坛上没有人会为你写应用程序。

假设您只有根时间轴,并且不重复第一帧,那么在应用程序的第一帧上使用以下代码:

//the shared object to store the state
var stateSO:SharedObject = SharedObject.getLocal("saveState");
if (stateSO.size > 0 && stateSO.data.lastFrame && stateSO.data.lastFrame != undefined) {
    //the shared object exists and has a valid value, so lets skip to that frame
    gotoAndPlay(stateSO.data.lastFrame);
}
//this function runs every frame
function saveState(e:Event = null):void {       
    stateSO.data.lastFrame = this.currentFrame; //assign the current frame number to the shared object
    stateSO.flush(); //save the cookie (shared object)
}
addEventListener(Event.ENTER_FRAME, saveState);

最新更新