Developing Webs logo
Web DW-Main DW-Photoshop
Visit the message board for solutions or post a question Check out the Classes offered for free at Developing Webs Voice Chat submit a tutorial, resources, article, font for publication consideration and earn a one way link back to your site Get more specifics about the Developing Webs Voice chat room and its room members View the current news at Developing Webs alternative sites which are resources for your d3evelopment needs Join Developing Webs Chat Link to us on your web page to help support this resource! Check out Developing Webs At yahoo groups! Developing Webs Home Adobe Photoshop Tutorials Macromedia Flash Tutorials Jasc Paint Shop Pro Tutorials Adobe Illustrator Animation basics Some Basic PHP tutorials Perl Tutorials HTML Tutorials Cascading Style Sheets javascript Front Page Tutorials Macromedia Dream Weaver Tutorials dreamweaver Publishing your site, FTP, ChMod, Promotions
RSS Newsfeed
for your site
DW News
DW Forum
Right click on button and copy shortcut

Add to My Yahoo!

Remember to book mark this site!

Request a Tutorial

Introduction to Variables

In a typical scripted movie, we have to manipulate everything from frame numbers,to movie clips,to buttons. In order to retrieve all the informationm we need to store it into variables. The primary information storage of Actionscript.

If you have taken algebra in math then you have written variables before. Let say y=x+3. "Y" will hold the value of 5. In programming terms, it will work the same way text=hi. When your proramming a project and you dont want to write down hi 50 times all you have to do is call in text and it will right Hi for you.

Variable Declaration

Creating a variable is called declaration. Declaration is like giving the variable a name. It can also be bringing the variable into existence. When a variable is declared i.e: var, it is empty. To close a variable you must declare a special value called undefined.(indicating the absence of data).

var text;

var movieclip;

var animation;

The word var tells us that were declaring a variable. Text follows the variable i.e: text, movieclip, and animation.

Variable Creation

Many languages require variables to be declared before data is deposited into them. Failure to do so will result in an error. If we assign a value to the variable that doesn't exist. It will automaticly creat one for you. However, doing so will make your code confusing and hard to read.

Legal Variables

ItMust be writtin exclusively of letters, numbers, and underscores.


No spaces, hypens, or punctuation.

It Must start with a letter ot an underscore

It must not exceed 255 characters.

Variables are case-sensitive

Legal Variables

var computer;

var counter:

var middle_name

Illegal Variables

var 1stplace

var my name

var 2-dimes

Dynamically Assaigned NamedVariables

Even though you will never use dynamically assaigned variables. You are still able to use it.

To create a variable name from any expression use the set statement. To show you how to use the set statement we will assign the value of "The Great1" to player1name

var i = 1

set ("player" + i + "name", "The Great1")

Arrays and objects, discussed later should be used instead of dynamic variables

Declare Variables at the Outset

It is very good to practice declaring your variables at the the beginning of your movie script, which is the first keyframe right after the preloader. Make sure you add a comment explaining each variables purpose. So your code won't get confusing.

// ^^^^^^^^^^^^^^^^^^^^
// Initialize variables
// ^^^^^^^^^^^^^^^^^^^^

var ballSpeed;// Velocity of ball, max 5
var score; // Player's current score
var hiScore; // High score (not saved between levels)
var player1; // Name of player 1, supplied by user

We can give variables an initial value at the same we create them

var ball speed = 5 ; //Velocity of ball, max 5

var score = 0 //Player's current score

var hiScore = o; //Hi Score(not saved between levels)


"Building The Web Into a Nicer Place -- One Site At A Time"
Developing Webs Group Copyright © 2001-2018 All Rights Reserved
Privacy and Legal