I have seen many people not knowing what variables are.
I think variables are very important to learn because they can be a great use.I will exaplin why you need to learn variables,how they work,and where/when you can use them.
What are variables?
The variable system has been added to flash since flash no.5.They are
usally used to ismplify scripts or to shorten codes.They are very often used with a boolean,true or false.Basicly,they can be anything you want.I sometimes type su=10; instead of speed_up=10;
How can variables be used?
They are mostly used with "onClipEvent(load){"The only difference between onClipEvent(load){ and onClipEvent(enterFrame){ is that onClipEvent(enterFrame){ performs an action every frame,meaning that if the frame rate is one,the action would be performed every frame.
They can be whatever you want as long as each variable has always got the same name.
Example:
onClipEvent(load)
{
teh_lolz = 5;
}
onClipEvent(enterFrame)
{
this._y -= teh_lolz;
}
That is a very simple code which make "this" go up by 5 pixels every frame.
Every time that "flash sees" teh_lolz.it takes it as a five.It is not hard to understand,is it?
"Why do I need to use variables?"
Sometimes,as the example I gave,you don't have to use variables.But sometimes you have to use ' em.
Example:
I want to make a RPG game,I know how to make a character move,but I want to know how to make him stop when there is a buiding.One of the choices would be to apply the same movement code but to the other direction.
Example:
onClipEvent(enterFrame)
{
this._x +=5;
if(this.hitTest(_root.rightwall))
{
this._x -=5;
}
}
But what if the speed changes during the game?In this case you have to use variables.Instead of reversin the speed,you can simply stop it with variables.
Example:
onClipEvent(load)
{
TehSpeed = 5;
}
onClipEvent(enterFrame)
{
this._x += TehSpeed;
if(this.hitTest(_root.rightwall))
{
TehSpeed=0;
}
else
{
TehSpeed=5;
}
}
I think you got the idea.The tutorial ends here. :o
