Copy link to clipboard
Copied
//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
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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?
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
Still doesn't work.
The code looks like this now. When the player1Score (for example) increases and I close the program and restarts it, everything is reset.
//The cookie
var store_stats:SharedObject = SharedObject.getLocal("store_stats")
var player1stats = player1Score
var player2stats = player2Score
store_stats.data.player1stats;
store_stats.data.player2stats;
store_stats.flush();
//Game stats
var nummer1:Number = 0;
var nummer2:Number = 0;
var player1Score = 0;
var player2Score = 0;
var isDeuce = false;
var isBattle = false
Copy link to clipboard
Copied
I cannot tell how that code relates to the code you showed earlier. For the code you just showed it will execute immediately before any value have a value
Copy link to clipboard
Copied
//The cookie
var store_stats:SharedObject = SharedObject.getLocal("store_stats")
stage.addEventListener(Event.ENTER_FRAME, flusher)
function flusher (Evt:Event) {
store_stats.data.player1stats = player1Score;
store_stats.data.player2stats = player2Score;
store_stats.flush();
}
//Game stats
var nummer1:Number = 0;
var nummer2:Number = 0;
var player1Score = 0;
var player2Score = 0;
var isDeuce = false;
var isBattle = false
Copy link to clipboard
Copied
It works fine for me. How are you accessing the scores to know that they are not what you expect them to be?
Copy link to clipboard
Copied
import flash.events.Event;
stop();
//The cookie
var store_stats:SharedObject = SharedObject.getLocal("store_stats")
stage.addEventListener(Event.ENTER_FRAME, flusher)
function flusher (Evt:Event) {
store_stats.data.player1rstats = player1score;
store_stats.data.player2rstats = player2score;
store_stats.data.player1stats = player1count;
store_stats.data.player2stats = player2count;
store_stats.flush();
}
//Game stats
var player1count = 0;
var player2count = 0;
var player1score = 0;
var player2score = 0;
var isDeuce = false;
var isBattle = false
//Shows board when not yet mouseEvent.
txtPoints1.txtPoints1.text=String(player1count);
txtPoints2.text=String(player2count);
player1set.text=String(player1score);
player2set.text=String(player2score);
//PLAYER 1
player1.addEventListener(MouseEvent.CLICK, score1);
function score1(Evt:Event){
if(isDeuce == true) {
txtPoints1.txtPoints1.text=("ADVANTAGE");
txtPoints2.text=("Disadvantage")
isDeuce = false
isDeuce == false;
return; //hopper ut at IFFEN
}
if (isBattle == false) {
player1count += 15;
}
if (player1count == 45) {
player1count -= 5;
txtPoints1.txtPoints1.text=String(player1count);
}
if (txtPoints1.txtPoints1.text == ("ADVANTAGE")) {
player1count = 55;
}
if (player1count == 55) {
trace("Round to Player 1");
player1score ++;
player1count = 0;
player2count = 0;
player1set.text = player1score
isBattle=false
}
txtPoints1.txtPoints1.text=String(player1count);
txtPoints2.text=String(player2count);
player1set.text=String(player1score);
checkDeuce();
}
//PLAYER 2
player2.addEventListener(MouseEvent.CLICK, score2);
function score2(Evtgsdrsfes:Event) {
if(isDeuce == true) {
txtPoints2.text=("ADVANTAGE");
txtPoints1.txtPoints1.text=("Disadvantage")
isDeuce = false
isDeuce == false;
return; //hopper ut at IFFEN
}
if (isBattle==false) {
player2count = player2count + 15;
}
if (txtPoints2.text == ("ADVANTAGE")) {
player2count = 55;
}
if (player2count == 45){
player2count -= 5;
}
if (player2count == 55){
trace("Round to Player 2")
player2score ++;
player2count = 0;
player1count = 0;
isBattle = false
txtPoints1.txtPoints1.text=String(player1count);
player2count = 0;
}
txtPoints2.text = String(player2count);
player2set.text = String(player2score);
checkDeuce();
}
//deuce
function checkDeuce() {
if (player1count >= 40 && player2count >= 40 && player1count == player2count) {
txtPoints1.txtPoints1.text = ("DEUCE!");
txtPoints2.text = ("DEUCE!");
isDeuce = true
isBattle = true //Disabling giveaway points(numbers)
;
}
}
Copy link to clipboard
Copied
I see where you assign 0 values to the variables every time the program starts, but I don't see where you assign the SharedObject values to those same variables, which is what I think you are wondering as to why it doesn't happen.
Copy link to clipboard
Copied
Yes, I think that's the problem. Every time the program starts, they're being set to 0. Therefore overwriting the stored SharedObject values in the same process, leaving the program in a reset state every time I start it. Any workaround for it?
To answer that last one: The SharedObject values are being assigned to the Game Stats variables at the top (isn't that correct?) by:
store_stats.data.player1rstats = player1score;
store_stats.data.player2rstats = player2score;
store_stats.data.player1stats = player1count;
store_stats.data.player2stats = player2count;
Or must I define the Game Stats variables before the SharedObject values, for them to "connect"? (with that I mean to move the variables above the values, in the script)
Find more inspiration, events, and resources on the new Adobe Community
Explore Now