cover
Flash Games Studio

cover
Flash Math Creativity


more

3 a.m. Tips
Simply Flashing

Christopher B. Contois

 

 

Home   |   PowerPoint   |   Flash   |  Links   |   About   |   Contact

Simply Flashing

Christopher B. Contois
2cinteractive.com



Submitted Question:
I don't know how to add the point system to a quiz. Can you give me a little help here? -Joyce

Tutorial- Creating a Score Counter

Download .fla - 36k

Objective:
To create a score field

Concept:
By supplying a variable name to the text field, you can write scripts which will control what is being displayed within that field.

Instructions:
There are 3 components to creating a score field.

1. The initiating variable
2. The actionScript which drives the change in score
3. The text field with the assigned variable

Step 1.
Starting from the top, open a new file, save it, add a layer named "actions", and place a script in frame 1 comment on you objective for the file.

Tip: Comment Tag
A "//" will turn your text pink and will allow you to write without it effecting your script.

If you are in "expert mode" you can write "/*" before your comment and end with "*/", this way you do not have to add a slash before every line.

Feel free to add whatever info will help you in the future. My comments usually include the following info:

// Title: score
// Author: Christopher Contois
// Date Modified: March 8, 2002
//
// Purpose: show how to add a score field
// and add and subtract different point from it
//
//btn=button
//mc=movie clip
//i=image
//txt=editable text
//-------------------------------

Following your file comments, we want to add a add the initiating variable. Create any name you like (i.e. score) and since most people begin scores at 0 we will set it to 0. You may want a reverse counter or to begin at 10,000. You may set the initiator to any number you like. This is the text that will initially display in your text field. The script is:

score=0;

You will see that my file has 2 frames. For this file I could have used one, however I recommend at least 2 with a stop or a loop because with larger files every time frame 1 is read your score will reset to 0. Be careful not to play this frame again unless you want to reset the score.

Step 2
Next draw 3 buttons on the stage. (If you are unsure how to create a button, visit the tutorial). The primary script on your button is:
--------------------------------
score = Number (score)+10;
--------------------------------

This line is stating the current score is now equal to the current score plus 10. The word "Number" is important, otherwise score would be equal to "score10", instead of "10". Depending how you want your score to increase and decrease you can add, subtract, multiply, divide, or use complex algorithm.

You can add this script to almost anything, buttons, hittests, enter frames, etc.

The script on your button should look like:
(remember the pink text are comments)

--------------------------------
//standard button command
on (release) {
      //the variable score now equals the number
      // of the variable score plus 10

      score = Number (score)+10;
   }
--------------------------------

Add this script to your other buttons and change the "+10" to be other amounts.

Step 3.
So far we have added the initiating variable and have created the means to alter it through a script. At this point the yor file will have keep the data, however you cannot see it on the screen without a text field.

Verify that your "Text Options'" panel is present. Create a new layer and name it (i.e. scoreField). Grab the text tool (the capital T) and draw a box on the screen. Without clicking anything else on the sceen go to your "Text Options'" panel and use the dropdown to select "Dynamic Text" and give your text field the smae variable name as your initiator variable name (i.e. score). If you want a background or border to your field you can select that too. Your panel should look like:



Test your movie. Congrats you have created a score field that is dynamically controlled through actionScript! If you have any questions or are unable to get your file to work feel free to email me.

Quick Ref:
1. Create a Movie Clip
2. Create Initiating Variable in Actions' layer - Frame 1
3. Place a "stop;" in Actions' layer - Frame 2
4. Draw Buttons
5. Place this script onto the button
//standard button command
on (release) {
      //the variable score now equals the number
      // of the variable score plus 10

      score = Number (score)+10;
   }
6. Make sure your "Text Options'" panel is present, add a layer and draw a text field.
7. On the "Text Options'" panel change the drop down from "Static Text" to "Dynamic Text"
8. Type a name in for the variable (i.e. score)
9. Test movie and have fun
 

-Christopher
email: ccontois@2cinteractive.com
url: www.2cinteractive.com


  Search
   
powered by FreeFind  
Copyright 2002. All Rights Reserved.

PowerPoint
ellenfinkelstein.com

bitbetter.com
presentations.com
microsoft.com
more

Flash
flashkit.com
actionscripts.org

flashguru.co.uk
flashplanet.com
more