# Variables

**URL:** https://forum.kirupa.com/t/variables/23374
**Category:** Uncategorized
**Created:** [June 17, 2003, 4:43am UTC](https://forum.kirupa.com/t/variables/23374 "2003-06-17T04:43:22Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![grimdeath](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/grimdeath/32/7124_2.png) [@grimdeath](https://forum.kirupa.com/u/grimdeath)
#### Post date: [June 17, 2003, 4:43am UTC](https://forum.kirupa.com/t/variables/23374/1 "2003-06-17T04:43:22Z")

</div>

Ok some of you might be surprised ive been using flash for 3 years already and i still dont know how or what do i use a variable for, ive bought a few books but these dont cover a basic explanation of how and what i can use these for and the benefits of using them, so im asking you my fellow brothers in flash which is the easiest way to learn what variables are and why should i use them

Ive browsed through [actionscript.org](http://actionscript.org), here and flashkit but i want something really dumbed down since ive never dealt with a variable before, i just want to basicaly understand what it is and then work my way up on its diffrent functions

Thanks guys :beam:

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [June 17, 2003, 4:51am UTC](https://forum.kirupa.com/t/variables/23374/2 "2003-06-17T04:51:32Z")

</div>

variables store values. Thats as about as basic as it gets.

You can have variables store numbers or strings.

```auto

// number...
myVar = 5;

// string....
myVar2 = "hello";

```

Thats really all they do. Then you can manipulate them as need. To add to a number variable:

```auto

myVar = 5;

myVar = myVar + 5;

// Now myVar = 10

```

To add to a string…

```auto

myVar2 = "hello";

myVar2 = myVar2 + "world!";

//Now myVar2 = "hello world!"

```

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [June 17, 2003, 4:56am UTC](https://forum.kirupa.com/t/variables/23374/3 "2003-06-17T04:56:22Z")

</div>

Ok so what good are these for on terms of animation or interaction??

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [June 17, 2003, 5:00am UTC](https://forum.kirupa.com/t/variables/23374/4 "2003-06-17T05:00:24Z")

</div>

animation? nothing. If you are just animating then you really won’t be using variables at all.

Interaction: everything.

Variables control everything. Take a look at some Actionscript and you’ll see how variables are the driving force behind every script. You may not know what the variable is doing there, but it needs to be there. It has a purpose, a job to do.

It really depends on what you need it for. Variables can do a myriad of different things. There is not cut-and-dry answer to your question…

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [June 17, 2003, 5:06am UTC](https://forum.kirupa.com/t/variables/23374/5 "2003-06-17T05:06:59Z")

</div>

hmmmmmmm im still confused lol, so variables are basically used for buttons or controlling movie clips??

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [June 17, 2003, 5:11am UTC](https://forum.kirupa.com/t/variables/23374/6 "2003-06-17T05:11:44Z")

</div>

All variables do is store information.

so really, instead of writing out the number 5 every time you need it in a script, its neater and easier to understand if you just put a variable there instead…

ok here is an example…

```auto

onClipEvent(load){
speed = 10;
}
onClipEvent(enterFrame){
this._x += speed
}

```

That code will move a movie clip to the right 10 points every frame. When programming longer scripts you would want to use variables to rwrite the information because it makes the code cleaner.

Here’s another code…

```auto

onClipEvent(load){
speed = 10;
friction = 0.98;
}
onClipEvent(enterFrame){
speed *= friction;
this._x += speed
}

```

This code multiplies speed times friction in every frame and eventually you will see that the movie clip stops moving because speed will eventually equal zero…

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [June 17, 2003, 5:14am UTC](https://forum.kirupa.com/t/variables/23374/7 "2003-06-17T05:14:15Z")

</div>

ok now i see why itsw better it helps for cleaner and simpler coding gotta get my as refrence book and do some more samples thanks thoug 😉

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [June 17, 2003, 5:30am UTC](https://forum.kirupa.com/t/variables/23374/8 "2003-06-17T05:30:46Z")

</div>

[http://www.actionscript-toolbox.com/flashmx\_variables.php](http://www.actionscript-toolbox.com/flashmx_variables.php)

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [June 17, 2003, 6:24am UTC](https://forum.kirupa.com/t/variables/23374/9 "2003-06-17T06:24:29Z")

</div>

You need variables in dynamic text boxes to have things appear in them and then reference them later in scripts.

If you want a counter in your script to count everytime that script is activated, like duplicateMovieClip for instance, you use:  
[AS]  
i++;  
[/AS]  
Variables can be strings, like what Jubba said, that you need to put the clock on my footer like:  
[AS]  
onClipEvent(enterFrame){  
now=new Date();  
h=now.getHours();  
m=now.getMinutes();  
s=now.getSeconds();  
if(h\>12){  
h-=12;  
}  
if(h==0){  
h=12;  
}  
if(m\<10){  
m=“0”+m;  
}  
if(s\<10){  
s=“0”+s;  
}  
\_root.display=h+":"+m+":"+s;  
}  
[/AS]  
And don’t even get me started on getTimer()!! Sorry, just wanted to chime in and say hi…:beam:
