Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

shared objects for score keeping 1

Status
Not open for further replies.

Flashoid

Technical User
Dec 11, 2002
163
US
Hello - I am trying to use Shared Objects for scoring and am not able to get it to work. I know how to use SO for entering names, (to create and write to the SO, and retrieving and displaying the SO data )but I can't figure out how to use it for scoring.

My goal is to create a single SO, and to write to it using an On (press) event to add and subtract points (+/- 10 points), and display this score (SO data) so the user can see it and when they leave and reenter the swf it displays their score. There would be multiple swf interactions writing to the same SO so the score SO would be read/written to by multiple swfs and the current score would be displayed as you enter different swfs.

Here's what I have so far. There would also be a dynamic text field labeled "score".


swf frame 1 code:
_root.score=0;



button code:

on (press) {

_root.score++;
if( init == null )
init = true;

so = SharedObject.getLocal( "score", "/");

if( (score != null) )
//checks if the input box contains data
{
so.data.score = score;
//gets input box variable content and updates shared object "score"
so.flush();
//sends new score input variable to the learner's local machine
}
}

}


Can anyone help me fill in the gaps??

thanks!


 
Am I on the right track with the code I have or not even close?
 
No luck yet but I will keep trying. Can you tell me how to control the score amount? I currently use: _root.score++;

I would like to be able to adjust the increments - currently using my code it would only add 1 point. I'd like to be able to adjust that amount.

thanks!
 
I found it. It's: _root.score += 100;

this should increase the amount by 100 each time.
 
I think I am close but now I am getting the NaN error displaying in the dynamic field - is there anyway to salvage what I have so far?

frame 1 code:
myObject.data.userName = userName_txt.text;
userName_txt.text = myObject.data.userName;
_root.score=0;
if( init == null )

init = true;
so = SharedObject.getLocal( "score", "/");

//if shared object has data already in it
if( (so.data.score != null) )
{
//gets data and stores in text box object
score = so.data.score


}


Correct answer button code:
on (press) {

_root.score += 10;
if( init == null )
init = true;

so = SharedObject.getLocal( "score", "/");

if( (score != null) )
//checks if the input box contains data
{
so.data.score = score;
//gets input box variable content and updates shared object "score"
so.flush();
//sends new score input variable to the learner's local machine
}



}


The dynamic field is labeled userName_txt and the variable for it is labeled score.

Is there a way to tweak what I have or add code related to NaN so it displays the numbers, not NaN?

This works when I publish it and just view the swf locally but once I upload to a server and try to view via browser I get the NaN error.


 
Would I add this bit of code or substitute something I already have in my code with it? I tried a number of combinations with no success.

thanks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top