保存&加载状态AS3 + Adob​​e Air

时间:2013-04-13 15:30:33

标签: actionscript-3 air save

如何使用Adobe Air保存和加载?这一直是我需要知道的事情。我之前已经问过这个问题,但是我已经被给了用什么而不是如何使用它。我在第59帧保存状态,我关闭并结束应用程序。然后,当我点击加载时,如何让它回到第59帧?请帮忙!

2 个答案:

答案 0 :(得分:0)

1.始终将当前帧写入sharedObject或文件

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

2.当应用程序启动时,首先检查文件或共享对象是否有上次保存的帧编号。如果默认情况下未找到,则为第一帧,否则为gotoAndPlay(frame_saved);

很抱歉,但在这个论坛上没有人会为你编写应用程序。你必须更多地努力完成解决方案。

答案 1 :(得分:0)

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

//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);
相关问题