1
votes

I am trying to create an Android application created using Adobe Flash Actionscript 3. I wanted each user of the app to input their name in the beginning of the application, then they have the capability to save their progress in current frame (and it will be saved into a save slot or similar). However, the problem arises when another user is going to use the app, he/she must enter a distinct username, and he/she can save anytime (and load his/her distinct load progress, different from the previous user.). And it goes on.

I am a newbie in programming and I hope you could help me. Any suggestions will be appreciated. Thanks!

This my code for creating a username and saving it:

function handleClick(Event:MouseEvent):void
{
    var myFirstVariable = boxOne.text;
    boxTwo.text = myFirstVariable;
    gotoAndStop("opening_scene")
}
myButton2.addEventListener(MouseEvent.MOUSE_UP, handleClick);

UPDATED EDIT 2: Here is my code for saving and loading. Still not working:

var so:SharedObject = SharedObject.getLocal("Test");
var userName:String = nameField.text;

if (so.data.users == null)
    so.data.users = new Object();

btnSave.addEventListener(MouseEvent.CLICK, onClick);
function onClick(e:MouseEvent):void
{
    if (so.data.users[userName] == null)
    so.data.users[userName] = new Object();
    so.data.users[userName].lastframe = currentFrame;
    so.flush();
    trace(userName);
}

btnLoad.addEventListener(MouseEvent.CLICK, reloadBtnClick);
function reloadBtnClick(e:MouseEvent):void
{
    if (so.data.users[userName] == null)return;
    if (so.data.users[userName].lastFrame == null) return;
    gotoAndStop(so.data.users[userName].lastFrame);
    trace(userName);
}
2
Well, if you can't do databases, you need to have a username stuffed into the savefile together with their frame. meaning you need another layer of object over mySharedObject.data that's user dependent. - Vesper
@Vesper could you give me a example code? Thanks - niagrafallsxxx
mySharedObject.data.users[i].currentframe, where i should be user dependent and stored somewhere when you load. - Vesper
@Vesper I am bit lost, I am sorry I am a newbie. Could you provide a sample code with two or more users? Thanks. - niagrafallsxxx

2 Answers

0
votes

I recommend that you use a SQLite Data Base to save your data can find all the documentation here Manipulating SQL database data Well is a little bit more complicate but works like have tables in Excel.

0
votes

As Vesper suggested, you need to have a storage with all the users you store. For example:

// Put user name here.
var userName:String;

var SO:SharedObject = SharedObject.getLocal("save");

// Create storage for users.
if (SO.data.users == null) SO.data.users = new Object();

// ...

function saveCurrentFrame(event:MouseEvent):void
{
    // Create storage for current user by their name.
    if (SO.data.users[userName] == null) SO.data.users[userName] = new Object();

    SO.data.users[userName].lastframe = currentFrame;
    SO.flush();
}

function getLastFrame(event:MouseEvent):void
{
    trace(1);
    // Skip this if there's no record for 
    if (SO.data.users[userName] == null) return;
    trace(2);
    if (SO.data.users[userName].lastFrame == null) return;
    trace(3);

    gotoAndStop(SO.data.users[userName].lastFrame);
    trace(4);
}