A lot of you were looking at me with a weird face when I said that you were going to learn variables in Flash. So here’s a more indepth explanation.

A variable is a symbol, or container, for another set of data. For instance, we can say the variable “myName” = Ryan Paul Thompson.

Do you remember when we started doing math in school? Once we got to Algebra, we started using variables. We would get problems such as “1 + b = 3″, and then we would be tasked with figuring out what “b” truly was (2 in this case).

Now in Actionscript 3, creating variables is a little bit different from in actionscript 2. We used to be able to get away with simply typing myname = “Simon Belmont”;

Not anymore. In actionscript 3we are REQUIRED to use the var keyword first.
Translation: Use var to tell flash, HEY!, I’m creating a variable!
example: var myVariable;
this creates a variable named “myVariable”

Next to note, is that you also have to define what KIND of variable this is, what is it’s data type. You can define a data type as a String, is it going to be Number, a boolean, etc.,etc.
Translation: You have to tell Flash what kind of data, the variable is representin.

example: var myWord:String = “Words flash will then remember, in the EXACT same way that you type them”;
This creates a variable named “myWord”, and flash understands that “myWord” is a “String” with a value of
“Words flash will then remember, in the EXACT same way that you type them”

example: var myNumericalValue:Number = 7;

This creates a variable named “myNumericalValue” that has a value of 7. Notice that 7 did NOT have quotation marks around it.
The second you put quotation marks around 7, flash understands it as a String, as a word, and can’t use it to count.

What good are variables? Let’s say you’re filling out an form…there is a variable that holds your email address, and pushes that data to a database so you’re client can receive that information. When you receive emails that say “Hello, Mike”, it’s pulling your information from a database full of variables. When you play Modern Warfare 2, and youg et a headshot, there are variables holding how many points that it was worth, and then adds your points up to level you up. The uses for variables are endless, and will become more apparent the farther along we go.

So that’s variables in a quick down and dirty nutshell.In the next lesson we’ll go over the trace command, and you can start putting those variables to use.

  • Share/Bookmark
blog comments powered by Disqus