[FONT=Trebuchet MS, Verdana, Arial][SIZE=2]Hey there! Now I haven’t written a tutorial in a while, so please excuse my screw-ups. Now… Let us begin.
[COLOR=Red][SIZE=3]What Is a Variable?[/SIZE]
[COLOR=Black]A variable is used to store information, which can be used later.
[COLOR=Red][SIZE=3]How do we use it?[/SIZE]
[COLOR=Black]In order to use it, we have to know the name of the variable. Let’s do something easy to start off.
Click on your frame and press ‘F9’ for the actions panel to come up.
Type in this code:
[/COLOR][/COLOR][/COLOR][/COLOR] Code:
myvariable = “Hi!”
trace(myvariable)
Now, the explaining.
myvariable represents our variable name; ‘=’ sets the value.
The quotes ("") represents that it is a string, and we set the string to ‘Hi!’.
Now I know what you’re asking - what the heck is ‘trace’?
Trace is a flash output command, which ONLY shows while developing, not when exported.
Press CTRL+ENTER to test it. Cool, right? Time to learn something better.
We’re gonna add to the variable.
Code:
myvariable = "Hi!"
myvariable += " You’re a fast learner!"
trace(myvariable)
Now this is easy to understand. We added:
Code:
myvariable += " You're a fast learner!"
Now, ‘+=’ adds to something. String or number, either way it’s ‘+=’.
To delete something, use ‘-=’.
Hey, you’re pretty good!
Now delete all of the code, so we can do another cool thing with variables.
[SIZE=3][COLOR=Red]Is there anything that’s actually useful with variables?[COLOR=Black]
[/COLOR][SIZE=2][COLOR=Black]Yeah, tons! For one thing, they’re used for health, magic and money in games.
Let’s do something ‘useful’ as you call it.
Make a button. You know how right? Draw what you want as the button, and select it.
Then press ‘F8’ and select ‘Button’.
Name it whatever you want. It doesn’t really matter to me.
Now put it on the frame.
Then click the text tool, and make it not too big, not too small.
Set the type of text to ‘dynamic’ and put the variable as ‘money’.
Put this code on your button.
[/COLOR][/SIZE][/COLOR][/SIZE] Code:
on(release){
money += 1;
}
On the frame, put this code.
Code:
var money:Number = 1;
That’s how to set a textbox variable - ‘var’ represents that it’s a variable, ‘money’ tells what the variable name is, ‘:Number’ tells what kind of variable it is going to be.
Knuxxie
[COMMENTS & CONSTRUCTIVE CRITICISM WELCOME]
[/SIZE][/FONT]