[COLOR=#000000][FONT=Arial]I have a dynamic text field that changes from 100 to 0 and vice versa when a button is clicked. I want this number to be saved when exiting the application, but it seems that it’s not returning the last clicked value when the application reopens. This is the code, any help please?
[/FONT][/COLOR][COLOR=#00008B][FONT=Consolas]import[/FONT][/COLOR][COLOR=#000000][FONT=Consolas] flash[/FONT][/COLOR][COLOR=#000000][FONT=Consolas].[/FONT][/COLOR][COLOR=#000000][FONT=Consolas]events[/FONT][/COLOR][COLOR=#000000][FONT=Consolas].[/FONT][/COLOR][COLOR=#2B91AF][FONT=Consolas]MouseEvent[/FONT][/COLOR][COLOR=#000000][FONT=Consolas];[/FONT][/COLOR]
[COLOR=#00008B]import[/COLOR] flash.media.[COLOR=#2B91AF]SoundChannel[/COLOR];
[COLOR=#00008B]import[/COLOR] flash.ui.[COLOR=#2B91AF]Mouse[/COLOR];
[COLOR=#00008B]var[/COLOR] saveDataObject:[COLOR=#2B91AF]SharedObject[/COLOR];
[COLOR=#00008B]var[/COLOR] currentScore:[COLOR=#2B91AF]Number[/COLOR];
options_mc.sound_btn.addEventListener([COLOR=#2B91AF]MouseEvent[/COLOR].CLICK, mute);
options_mc.test3.addEventListener([COLOR=#2B91AF]MouseEvent[/COLOR].CLICK, test3);
init();
[COLOR=#00008B]function[/COLOR] mute([COLOR=#00008B]event[/COLOR]:[COLOR=#2B91AF]MouseEvent[/COLOR])
{
[COLOR=#00008B]if[/COLOR](currentScore == [COLOR=#800000]100[/COLOR])
{
currentScore = [COLOR=#800000]0[/COLOR]
options_mc.onoff_txt.text = [COLOR=#2B91AF]String[/COLOR](currentScore);
}
[COLOR=#00008B]else[/COLOR] [COLOR=#00008B]if[/COLOR](currentScore == [COLOR=#800000]0[/COLOR])
{
currentScore = [COLOR=#800000]100[/COLOR]
options_mc.onoff_txt.text = [COLOR=#2B91AF]String[/COLOR](currentScore);
}
saveData();
}
[COLOR=#00008B]function[/COLOR] init():[COLOR=#00008B]void[/COLOR]
{
saveDataObject = [COLOR=#2B91AF]SharedObject[/COLOR].getLocal([COLOR=#800000]"test"[/COLOR]);
currentScore = [COLOR=#800000]100[/COLOR];
[COLOR=#00008B]if[/COLOR] (saveDataObject.data.savedScore == [COLOR=#00008B]null[/COLOR])
{
trace([COLOR=#800000]"No saved data yet."[/COLOR]);
saveDataObject.data.savedScore = currentScore;
}
[COLOR=#00008B]else[/COLOR]
{
trace([COLOR=#800000]"Save data found."[/COLOR]);
loadData();
}
}
[COLOR=#00008B]function[/COLOR] saveData():[COLOR=#00008B]void[/COLOR]
{
saveDataObject.data.savedScore = currentScore;
trace([COLOR=#800000]"Data Saved!"[/COLOR]);
saveDataObject.flush();
trace(saveDataObject.size);
}
[COLOR=#00008B]function[/COLOR] loadData():[COLOR=#00008B]void[/COLOR]
{
[COLOR=#00008B]if[/COLOR](currentScore == [COLOR=#800000]100[/COLOR])
{
currentScore = saveDataObject.data.savedScore;
trace([COLOR=#800000]"Data Loaded!"[/COLOR]);
}
[COLOR=#00008B]else[/COLOR] [COLOR=#00008B]if[/COLOR](currentScore == [COLOR=#800000]0[/COLOR])
{
currentScore = saveDataObject.data.savedScore;
} [COLOR=#000000][FONT=Consolas]}[/FONT][/COLOR][COLOR=#000000][FONT=Arial]
[/FONT][/COLOR]