Skip to main content
May 17, 2014
Question

Can't get SharedObject to work..

  • May 17, 2014
  • 1 reply
  • 508 views
Basically I've created a score counting program in ActionScript 3, and I want to save the points when I close the program. But I don't understand why the code isn't working..

//The cookie

var store_stats:SharedObject = SharedObject.getLocal("store_stats")

stage.addEventListener(Event.ENTER_FRAME, flusher)

    function flusher (Evt:Event) {

        store_stats.flush();

        store_stats.data.player1stats = player1Score;

        store_stats.data.player2stats = player2Score;

    }

   

trace(store_stats);

//Game stats

var nummer1:Number = 0;

var nummer2:Number = 0;

var player1Score = 0;

var player2Score = 0;

var isDeuce = false;

var isBattle = false

And how to I write on the forum with code font?
This topic has been closed for replies.

1 reply

Ned Murphy
Legend
May 18, 2014

What aspect of the code is not working?

Move that flush() command after you assign the data if the intention is to save that data to the SharedObject.

May 18, 2014

When I publish the program and run the swf file, it doesn't save the info till next time I open the program...

Move the flush() command?

Ned Murphy
Legend
May 18, 2014

Yes, the flush() command is what saves the data.  Since you have it placed before the two lines where you assign the data, it is not saving the data you assign... it is saving the previous value if there was any.