I have created a trivia game for my website wiht 20 questions. Each question has a label on the timeline where the question and options are and then there is a correct and a wrong page (label) for each question. When the user selects the correct answer they are taken to the Correct page for that question and if they click an incorrect answer they are of course taken to the Wrong page for that question.
I would like to make it so when they click the correct answer of a question not only does it take them to the "correct" page, but I would like it to update a counter in memory. At the very end of the game I would like to display the number of questions they got correct.
I have been looking at a ton of discussions and trying different things but cannot get it to work.
There is a lesson called 'Extend' in the lessons panel which teaches about creating and storing variable values.
If you have not yet gone through it ,check it out .
Another simple way to keep track of a variable is to put a global variable on Stage.compositionReady. You can then iterate that variable, and access it from anywhere in your application.
// code on stage.compositionReady: --------------------
sym.myScore = 0;
// code anywhere else in your app where you want to add 1 point to your score: --------------------
sym.getComposition().getStage().myScore += 1;
// code anywhere else in your app where you want to display your score: --------------------
var tempMyScore = sym.getComposition().getStage().myScore;
sym.$("myText").html("myScore is = "+tempMyScore);
// or this, depending on how your symbol is nested: sym.getSymbol("myParentSymbol").$("myText").html("myScore is = "+tempMyScore);
** Edit: I see Hemanth answered your question in this other thread: http://forums.adobe.com/thread/1456349?tstart=0. His example of using sym.setVariable("counter",0); and sym.getVariable("counter"); is pretty sweet!