logo
g Text Version
Beauty & Self
Books & Music
Career
Computers
Education
Family
Food & Wine
Health & Fitness
Hobbies & Crafts
Home & Garden
Money
News & Politics
Relationships
Religion & Spirituality
Sports
Travel & Culture
TV & Movies

dailyclick
Bored? Games!
Nutrition
Postcards
Take a Quiz
Rate My Photo

new
Houseplants
Romance Movies
Creativity
Family Travel
Southwest USA
Irish Culture
Home Finance


dailyclick
All times in EST

Full Schedule
g
g Flash and Animation Site

BellaOnline's Flash and Animation Editor

g

The Flash ActionScript Variable


The variable is the workhorse of any programming language. In Flash, it is one way that ActionScript can talk to the Flash program. Because ActionScript is based on the ECMAScript international standardized programming language for scripting, it makes sense that ActionScript will work in the same way as other scripting languages. So what is a variable and how does it work in ActionScript? You can think of a variable as a container or storage box for information. When you place information inside a variable, this is called assigning a value to the variable. The value, or information, will stay there until you change the value in some way by writing more ActionScript.

How do you create a variable in ActionScript? The easiest way is to use the variable in your program. Flash will recognize that it has never encountered this variable before and will make it "official". Although this method works and is perfectly acceptable, most programmers find it helpful to maintain more control. One way is by defining a variable using the var keyword. For example, let's create a variable that we will call "container" and assign to it an initial value to 20. Here is the code. Let's take a look at it and then break it down.

var container;
container = 20;

Notice that both lines of the code above end with a semicolon. The semicolon ends a line of program code much like a period ends a sentence. If you do not use the period at the end of your sentences, no one will be able to tell when one sentence ends and the next one begins. It's the same with programming. Don't forget those semicolons.

Let's take a look at the first line of code. It begins with the var keyword which is followed by the name we want to give to our variable. It is telling Flash that we are creating a new variable and we are naming it "container".

The second line of code assigns an initial value to the variable. This code might look familiar to those of you who have studied algebra. In algebra, x = 1 means that "x is equal to 1". The equal sign means "equal to" in algebra. However in ActionScript, the equal sign means "assign the value". Therefore, the second line is telling Flash to assign the value of 20 to the variable named "container".

Tip:
The two lines of code above can be condensed into one line.
var container = 20;




Add The+Flash+ActionScript+Variable to Twitter Add The+Flash+ActionScript+Variable to Facebook Add The+Flash+ActionScript+Variable to MySpace Add The+Flash+ActionScript+Variable to Del.icio.us Digg The+Flash+ActionScript+Variable Add The+Flash+ActionScript+Variable to Yahoo My Web Add The+Flash+ActionScript+Variable to Google Bookmarks Add The+Flash+ActionScript+Variable to Stumbleupon Add The+Flash+ActionScript+Variable to Reddit



 



RSS | Related Articles | Editor's Picks Articles | Top Ten Articles | Previous Features | Site Map


For FREE email updates, subscribe to the Flash and Animation Newsletter


Past Issues


print
Printer Friendly
bookmark
Bookmark
tell friend
Tell a Friend
forum
Forum
email
Email Editor


Content copyright © 2014 by Diane Cipollo. All rights reserved.
This content was written by Diane Cipollo. If you wish to use this content in any manner, you need written permission. Contact Diane Cipollo for details.

g


g features
Add Static Text To Craft Product Trailer Template

Drop Zones and Transitions in Motion 5

Craft Product Template - Background Layer

Archives | Site Map

forum
Forum
email
Contact

Past Issues
memberscenter


vote
Poetry
Daily
Weekly
Monthly
Less than Monthly



BellaOnline on Facebook
g


| About BellaOnline | Privacy Policy | Advertising | Become an Editor |
Website copyright © 2014 Minerva WebWorks LLC. All rights reserved.


BellaOnline Editor