如何保存动态文本?

时间:2013-11-16 02:14:54

标签: actionscript-3 flash

我有一个动态文本字段,当单击一个按钮时,该字段从100变为0,反之亦然。我希望在退出应用程序时保存此数字,但似乎在应用程序重新打开时它不会返回最后一次单击的值。这是代码,有什么帮助吗?

import flash.events.MouseEvent;
import flash.media.SoundChannel;
import flash.ui.Mouse;

var saveDataObject:SharedObject;
var currentScore:Number;
options_mc.sound_btn.addEventListener(MouseEvent.CLICK, mute);

options_mc.test3.addEventListener(MouseEvent.CLICK, test3);
init();
function mute(event:MouseEvent)
{

if(currentScore == 100)
{
currentScore = 0
options_mc.onoff_txt.text = String(currentScore);

}
else if(currentScore == 0)
{
currentScore = 100
options_mc.onoff_txt.text = String(currentScore);
}
saveData();
}
function init():void
{

saveDataObject = SharedObject.getLocal("test");
currentScore = 100;




if (saveDataObject.data.savedScore == null)
{
    trace("No saved data yet.");
    saveDataObject.data.savedScore = currentScore;
}
else
{
    trace("Save data found.");
    loadData();
}


}

function saveData():void
{
saveDataObject.data.savedScore = currentScore;
trace("Data Saved!");
saveDataObject.flush();
trace(saveDataObject.size);
}

function loadData():void
{
if(currentScore == 100)
{
currentScore = saveDataObject.data.savedScore;
trace("Data Loaded!");
}
else if(currentScore == 0)
{

    currentScore = saveDataObject.data.savedScore;
}
}

2 个答案:

答案 0 :(得分:0)

function loadData():void
{
    currentScore = saveDataObject.data.savedScore;
    trace("Data Loaded!");
    if (options_mc.onoff_txt) options_mc.onoff_txt.text=String(currentScore);
}

显然你错过了立即将分数写入文本字段的行。你似乎在做拯救权。

答案 1 :(得分:0)

As3 (输入文本) (动态文本) (保存按钮)

If input text not blank 
    Saved //
If input text blank
    Loaded //
If moving next frame
   Dynamic text still exists //
If reopen app
    Loaded
相关问题