Adding Values in Flash

Posted on 2012-08-24
Medium Priority
Last Modified: 2012-08-29
Current project includes a ten page quiz.
Each question has a choice of three answers, each is related to a colour ( red,amber,green)
When a question choice is made a box is populated by a colour fill and goes to the next
question frame. As the questions are answered the boxes progress across the stage until the final box.
I need to find a way to add up which colour has filled the most boxes and the move to the appropriate frame with a statement that relates to total.
Question by:Fairfax103

Accepted Solution

Gabriologist earned 1500 total points
ID: 38332219
The 'box fill' is a visual cue for the user, I'm guessing - telling them how they did for that question. But 'underneath' the visual skin of the program you just need some sort of counter that keeps track of the responses.

So I can think of 2 ways to do this.

1) You initialise a variable to record a score - let's call the variable 'totalScore'. You assign a value to each of the colours - for example, red = 0, amber = 1, green = 2. So when a user answers with a 'green' answer your code would be

totalScore = totalScore + 2;

or if they answer an amber answer the code would be

totalScore = totalScore + 1;

You keep track of the score, and end up with a total score after all the questions have been asked. You can then take a decision on what feedback to give based on what score they got versus the maximum score possible.

You say there are 10 pages, so if we used this marking scheme, the maximum score would be 20 - all green. So you might 'split' the feedback at a score of 5, 10 and 15. You then just need a bunch of 'if' statements something like

if (totalScore <= 5) {
     ...take some actions here

if ((totalScore > 5) && (totalScore < 10)) {
     ...take some actions here

if ((totalScore >= 10) && (totalScore < 15)) {
     ...take some actions here

if (totalScore >= 15) {
     ...take some actions here


2) Setup three variables to record the 'colour' of each answer - we'll call them 'redAnswer' 'amberAnswer' and 'greenAnswer'. Before the quiz starts we set them all to 0

var redAnswer = 0;
var amberAnswer = 0;
var greenAnswer = 0;

Then each time you get a 'red' answer you use the code

redAnswer = redAnswer + 1;

and if you get an amber answer you use

amberAnswer = amberAnswer + 1;

and I'm sure you can work out what code you need if you get a green answer.

At the end of the quiz, you just need to compare the three variables to see which is largest. Bear in mind that using this method, it's quite likely that two of the variables will be the same value, so you'll have to think what decision needs to happen in that case. Note that all three variables can never be the same since 10 (the number of questions) cannot be divided equally when using whole numbers only.

Author Closing Comment

ID: 38344948
Thanks a lot

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is primarily concerned with ActionScript 3 and generally specific to AVM2.  Most suggestions would apply to ActionScript 2 as well, and I've noted those tips that differ between AS2 and AS3. With the advent of ActionS…
I have been doing hardcore actionscripting for some time; and needless to say I have faced a lot of problems in just understanding others' code rather than understanding what the code executes. A programmer's life can become hell when there are a lo…
The goal of the tutorial is to teach the user how to how to record live broadcast.
The goal of the tutorial is to teach the user how to set there setting in Adobe Flash Media Live Encoder and YouTube for optimal video and audio quality.
Suggested Courses

864 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question