Flash Essential

AS3 Guide Variables

Jul 30th 2008
8 Comments
respond
trackback

Show Navigation || Hide Navigation

Variables

Information has to be stored somewhere if it's to be used later. In Actionscript 3.0 information is stored in containers called variables. For example you might need to store a list of usernames and passwords for your application and with use of variables this makes it all possible. Below is an example of simple a variable that contains a string of characters that contain the words Flash Essential.

var firstVariable:STRING = "Flash Essential";
  • When you create a variable in ActionScript 3, you must use the
    var

    keyword.

  • We then give it a unique name of our own choice so that we can distinguish if from other variables. In the code above I have called mine firstVariable.
  • After our semi-colon we select a Data Type, this tells Flash what type of data is going to be stored in the above example I have used a STRING which indicates text or a string of characters.
  • Inside the string I have typed Flash Essential

This is just one example of a data type but their are many more, over the course you will become more and more familiar with them so don't be to intimidated if you keep seeing unfamiliar and different data types. It will soon become second nature to you.

Some more variable examples

var secondVariable:Number = 2;
var thirdVariable:Boolean = True;
var fourthVariable:Array = ["one", "two", "three"];

Notice I have named all the variables with a lowercase letter on the first word and a capital letter for the second word. These are some common practices when writing variables their are however other rules to take note of. They can only include alphanumeric characters and must only be one word.

So to conclude variables allows us to store data and use it later on in our code. It essentially gives our script a memory and the ability to remember types of data.


This post is tagged , ,



Sponsors

Explore Recent





Monthly Archives



Friends and Affiliates



8 Comments

Leave a Reply