samedi 27 février 2016

How to fix or correctly make an undo button using sharedObject, without the 2 shared objects syncing?

In short i'm trying to make an undo button by using 2 save files, it's probably something really simple but i just can't seem to see why i'm getting the same data in both shared objects.

Ideally i would like the first mouse click to save array = [0] into load1dataobject

the second to save array [0,1] into load2dataobject

the third to save array[0,1,2] into load1dataobject //here if i used undo, i'd want to load load2dataobject which was array [0,1]

and so forth...

thanks in advance

import flash.net.SharedObject;

var load1DataObject:SharedObject = SharedObject.getLocal("Undo1");
var load2DataObject:SharedObject = SharedObject.getLocal("Undo2");
var array:Array = [];
var undoFunctionSwitch = 0;
var i = 0;

stage.addEventListener (MouseEvent.CLICK,clicked);

function clicked (MouseEvent)
{
        array[i] = i;
        i ++;
        undoFileSwitch ();

        trace (load1DataObject.data.array);
        trace (load2DataObject.data.array);
}

function undoFileSwitch ()
{
        if (undoFunctionSwitch == 0)
        {
                trace ("saved1");
                saveFile1 ();
                undoFunctionSwitch++;
        }
        else
        {
                trace ("saved2");
                saveFile2 ();
                undoFunctionSwitch--;
        }
}

function undoFile ()
{
        if (undoFunctionSwitch == 0)
        {
                loadFile1 ();
        }
        else
        {
                loadFile2 ();
        }
}

function saveFile1 ()
{
    load1DataObject.data.array = array;
    load1DataObject.flush();
}

function saveFile2 ()
{
    load2DataObject.data.array = array;
    load2DataObject.flush();
}

function loadFile1 ()
{
        array = load1DataObject.data.array;
}

function loadFile2 ()
{
        array = load1DataObject.data.array;
}

Aucun commentaire:

Enregistrer un commentaire