What are variables and how do i use them?

posted: 04-02-06
author: PrimeVector
website: http://www.free-webmaster-resource.com
views: 4773
comments: 0
total pages: 1



Check This Amazing Traffic Generating Widgetsl 4 Webmasters!

What are variables and how do i use them?

If you just entered this whole world of codes and programming, then you might be intimitated by all those terms that are used daily in those area's and thus in most tutorials. In this tutorial i want to teach you a bit about one of the most basic things in coding that you will without a doubt be using yourself all the time. Its variables.

Variables are like little containers to remember and store things for us. So lets say i wanted to store my name in a variable then in Actionscript i would just do this:

var name = "PrimeVector";


'var' means that we are about to declare a variable, in our case called 'name'. This variable is then filled with the string "PrimeVector". To keep things clean you need to place a ';' at the end of each line of code.

At this point you have a filled variable and could start doing some stuff with it. Like if you wanted to trace an output to the screen if ran inside Flash then you could place this line of code under it.

trace(name);


'trace' is a very useful function in Flash and should not be underestimated. With it you can check if things are going like they should be at or in this case check if our variable called 'name' is actually filled with the string "PrimeVector". If you would run this code then you would see a trace output on your screen displaying the contents of variable name ... in our case it would show "PrimeVector"

Be aware

Never give names to your variables starting with a number. So '4enemy' is a bad name, but 'enemy4' is perfectly legit. Also never give them names that are already in use by Flash itself, for example 'button'.

When you make up names for your variables try to keep them descriptive and not very crypic. Like for example when you have a enemy in a game and you want to create some variable describing how many bullets are left on that enemy, then you should setup a variable like 'enemyBulletsLeft' or something along those lines. You should not make it cryptic looking like 'ebl' or other non descripive names like that. This is because when your codes start to grow you will create some nice quite un-readable codes for yourself if you keep naming your variables very un-descriptive.

Some variable magic

Lets say you wanted to use variables to store numbers and results of a mathmatical process like addition. Lets look at the example below:

var numberA = 5;
var numberB = 5;
var additionResult = numberA + numberB; //additionResult would be 5 + 5 = 10

Here is the same code but with a few traces to check whats going on!

var numberA = 5;
trace("The content of variable numberA is:" + numberA);

var numberB = 5;
trace("The content of variable numberB is:" + numberB);

var additionResult = numberA + numberB;
trace("numberA added to numberB = " + additionResult);


If you would copy and paste the above code into a flash file and run it, then variable 'numberA' will be added to variable 'numberB' and the result is placed in another variable called 'additionResult'. So in the end variable 'additionResult' will have a value of 10.

We again declare the variables with 'var', we name it and fill it. As you can see this opens a lot of possibilities. You cant even really do anything without the use of variables. I also put in a few traces so you can see how the code is trigged. From top to bottom and in the end the numbers you wanted are added and the result stored.

Conclusion

I hope this little exercise in variables could help you on your way. If you have any questions please don't be shy and post a message in the forum.



Warning: include() [function.include]: URL file-access is disabled in the server configuration in /home/freeweb/public_html/tutorials/flash/basics/tutorial005/index.php on line 312

Warning: include(http://...@SF_random.php) [function.include]: failed to open stream: no suitable wrapper could be found in /home/freeweb/public_html/tutorials/flash/basics/tutorial005/index.php on line 312

Warning: include() [function.include]: Failed opening 'http://...@SF_random.php' for inclusion (include_path='.:/usr/lib/php:/usr/local/lib/php:/usr/lib/ZendGdata/library') in /home/freeweb/public_html/tutorials/flash/basics/tutorial005/index.php on line 312



Amazing Webmaster Widgets






Comments

sorry no comments were found, you could be the first to leave a comment !



- Press here to view all available smilies!



Latest News

Amazing Webmaster Tool

If you run a MySpace or teens related site with visitors interested in GLITTERS you will need this great tool: Webmaster Glitter Tool It will generate backlinks at an amazing pace!

 

Useful Click To Clipboard Script

This is a nice little copy to clipboard script. You can find it here!

 

Google Pages

Create pages on google quick and easy with Google Pages!

 

My Funny Pictures Site

Have fun on this funny pictutures site i made, i hope youll enjoy it :) PixHumor

 

IS YOUR CHILD SAFE???

With this great program you can make sure your child will be a lot safer while browsing the Internet.

 

New Site

I created a fun site for MSN Messenger Stuff called MSN Freak. You can find the site here: Free Winks @ MSN Freak

 

Useful free unlocker tool

This tool is a very useful tool that runs in the background. Whenever you try to for example copy a folder and explorer sceams at you it wont do that, the barrier is lifted and you can continue to do what you wanted too. Download it here.

 

GOOGLE worldwide: Languages and countries

Useful page showing all the Google Search Engines of all countries. Check it out here.

 

Google Trends

Google trends enables us to see where people want certain things the most. You can enter a keyword and find out where people search for that most often! Check Google Trends

 

Google PageRank Checker

I personally enjoy this Google pagerank checker a lot: Google PageRank Checker

 

New tutorials

I added a new basic Flash tutorial showing how to create a simple motion tween. You can find it here: Basic Flash Motion Tween

 

2 new Flash tutorials

I added 2 new Flash tutorials to the tutorial selection. On deals with the if else conditional statement and the other deals with setting up a bit of color with actionscript. You can checkout the tutorials here: Actionscript and colors and If Else Conditionals.

 

Oh My!

Its mad times overhere, im helping promote and have created a few sites which has taken quite some time from me. site1: http://www.flashgamefreak.com, site2 http://www.freewinks.net, site3 http://www.smilieworx.com and more are to come this and next week. This has taken its toll on my time to write tutorials. I will make up for that as soon as possible. Thanks for your understanding.

 

Basic Flash Tutorials

I added 3 new basic Flash tutorials to the tutorial list. Dealing with layers, What are functions and one about The Registration Point.

 

A bit of a delay

I have had a very crazy time around here the last month, because of this some tutorials have not been written yet. This is a list of tutorial i still need to write and you can expect them in the very near future.

 

Advertise on FWR

If you want to advertise here then please contact me here. We can make a nice deal and you can get stats on them how often you would like.

 

2 new tutorials

2 new web design related tutorials were added ... more Flash tutorials are on their way but its a bit mad around here these last days ;)

 

View All News



In Focus

Free Auto Insurance Quotes!
Saving money with InsureMyCar4Less is simple. After you fill out our quick online form, you get free auto insurance quotes from the best providers in the industry. They compete for your business, and you save money.
Save money on your Auto Insurance!
You could be paying too much for your auto insurance, find out here if you qualify for HUGE savings!
Play Aztec Quest online for free!
Play Aztec Quest online for free!
Get free Auto Insurance Quotes!
Saving money with InsureMyCar4Less is simple. After you fill out our quick online form, you get free auto insurance quotes from the best providers in the industry. They compete for your business, and you save money.
Play World War 2 Commando Free!
Play World War 2 Commando online for free!
Play Swat 2 Now
Play the swat 2 game and shoot those bad guys!
Play Bubble Boomers
Pop the bubbles of the like colors for this very fun and addictive game for FREE!!!
Stop identity theft in its tracks!
Protect My ID makes it easy for you!
Play Airstrike 1941 online for free!
Play Airstrike 1941 online for free!
Test Handyman Tools and Keep them!
We're looking for a few good product testers for our Handyman club. Test out all sorts of tools and keep them!
Play Frogger Now!
Play frogger with 1 click download of gamevance!
Get a Free Auto Insurance Quote
Free quotes from top insurance carriers!
Save up to 70% on auto insurance!
Do you qualify for 60-70% off your auto insurance rates? Find out right now! Request quotes 24 hours a day with our secure online form. It's super fast and easy. See what your rate is absolutely free!
Customize your Facebook with a theme
Customize the colors and music on your facebook profile page today!
Do you like to go Fishing?
We're looking for a few good product testers to test our Fishing gear. Keep it afterwards!
Play Pac Man right here!
Get all the hottest new games and all the old school games in one place!
Test Hunting Gear and Keep It!
We're looking for a few good product testers for our Hunting Gear!
Play the old school Baseball Stars
Get all the hottest new games and all the old school games in one place!
Play Streetfighter Now!!!
Get all the hottest new games and all the old school games in one place!
Get a FREE Apple iPad Now!!!
You know you want your FREE Apple iPad right here!
Share your Opinion, win $50,000?
Share your Opinion, win $50,000? Couldn't get any easier! It's free and fun!
Need New Contact Lenses for FREE?
Treat your eyes to all day comfort with a free trial and save up to $100!
Save Money on Airline Fares Here!
Save up to 50% off on major airline brands here!

Cool Stuff