0
\$\begingroup\$

I am making a flash game in which i have a variable levelState that describes the current level in which user has entered I am using SharedObject to save the progress but it does not do so first i declred a clas level variable

private var levelState:Number = 1;
private var mySaveData:SharedObject = SharedObject.getLocal("levelSave");

in the Main function i am checking if it is a first run of the game like below

if (mySaveData.data.levelsComplete == null)
    {
        mySaveData.data.levelsComplete = 1;
    }

and in a function where the winning condition is checked so that levelState could be increased i am usin this sharedobject to hold the value of levelState

if (/*winniing condition*/)
    levelState++;
    mySaveData.data.levelsComplete = levelState;
    mySaveData.flush();
    setNewLevel(levelState);
}

but when i play the game clear a level and again run the game it does not start from that level it starts from beginning.

\$\endgroup\$
1
\$\begingroup\$

Solution Actually in the main function i have to assign the levelState the value from the ShredObject . In the first part of the above code i added some lines like this

if (mySaveData.data.levelsComplete == null)
{
    mySaveData.data.levelsComplete = 1;
} else {
   levelState = mySaveData.data.levelsComplete
}

That else part i was missing

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.