2013-04-13 30 views
1

如何使用Adobe Air保存和加載?這一直是我需要知道的。以前我問過這個問題,但是我已經給了要使用的東西,但不知道如何使用它。我保存第59幀中的狀態,關閉並結束應用程序。那麼當我擊球時,我怎樣才能回到第59幀?請請幫忙!保存並加載狀態AS3 + Adob​​e Air

+0

此外,這是對移動。 – user1666767

+0

您可以使用SharedObjects在會話之間存儲數據(例如幀號) - 請參閱http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/net/SharedObject.html – 2013-04-13 16:18:32

+0

您是否發現瞭解決你的問題?如果是這樣,請分享它,或接受現有的答案。 – BadFeelingAboutThis

回答

0

1.Always寫你的當前幀的共享對象或文件

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

2,當應用程序starte首先檢查文件或共享對象最後保存的幀數。如果默認情況下沒有找到它是第一幀,否則gotoAndPlay(frame_saved);

對不起,但在這個論壇上,沒有人會爲你寫的應用程序。你必須更多地努力完成解決方案。

+0

我不明白! – user1666767

+0

@ user1666767:你看看Lee Burrows的鏈接嗎? – puggsoy

+0

是的,我知道如何使用SharedObjects,但我將如何保存和加載!它是如何檢測哪一幀的! – user1666767

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);