# Noobie variable questions

**URL:** https://forum.kirupa.com/t/noobie-variable-questions/119310
**Category:** Uncategorized
**Created:** [August 13, 2004, 10:31am UTC](https://forum.kirupa.com/t/noobie-variable-questions/119310 "2004-08-13T10:31:52Z")
**Posts on this page:** 16
**Page:** 1

<div class="post-metadata">

### Author: ![LunarTears](https://avatars.discourse-cdn.com/v4/letter/l/4bbf92/32.png) [@LunarTears](https://forum.kirupa.com/u/LunarTears)
#### Post date: [August 13, 2004, 10:31am UTC](https://forum.kirupa.com/t/noobie-variable-questions/119310/1 "2004-08-13T10:31:52Z")

</div>

I can’t figure out these variables in whatever timelines ☹  
If I had something like  
MAIN TIMELINE  
mini = 10;

MC TIMELINE  
trace(mini);

it displays undefined, right?  
so do I ALWAYS have to make it a

trace (\_root.mini);

for it to display 10?

and, what’s the difference between

var sweetness = 10  
and  
sweetness = 10  
?

I read the tutorial and all, but that confused me even more if anything ☹  
Aslo, since I’m already asking questions, gotoAndPlay(nextFrame) is the same thing as nextFrame alone, right?  
How do I have it play the nextframe in a MC without having to type the number every time?  
It’s a hassle to go and change the the numbers after you change the length of your frames.  
I guess if you do something like this:

framemove = \_currentframe+1

gotoAndPlay(framemove);

but what other ways are there?

---

<div class="post-metadata">

### Author: ![APDesign](https://avatars.discourse-cdn.com/v4/letter/a/e47c2d/32.png) [@APDesign](https://forum.kirupa.com/u/APDesign)
#### Post date: [August 13, 2004, 10:41am UTC](https://forum.kirupa.com/t/noobie-variable-questions/119310/2 "2004-08-13T10:41:03Z")

</div>

to answer your first question, yes… you must always use \_root.variable to access the variable if it is on the main timeline and you are in a movies scope. If you do a search on \_parent you can use that instead of \_root also.

The difference between var variable\_name=10 and just variable name=10 is that the var is a “temporary” variable, you use var variable\_name=10 in functions so that once the function is over it deletes the variable.

Hope that helped a bit.

---

<div class="post-metadata">

### Author: ![Prophet](https://avatars.discourse-cdn.com/v4/letter/p/838e76/32.png) [@Prophet](https://forum.kirupa.com/u/Prophet)
#### Post date: [August 13, 2004, 6:08pm UTC](https://forum.kirupa.com/t/noobie-variable-questions/119310/3 "2004-08-13T18:08:19Z")

</div>

regarding your last question, whats wrong with the following AS:

```auto
play()

```

😉

Prophet.

---

<div class="post-metadata">

### Author: ![LunarTears](https://avatars.discourse-cdn.com/v4/letter/l/4bbf92/32.png) [@LunarTears](https://forum.kirupa.com/u/LunarTears)
#### Post date: [August 14, 2004, 8:18am UTC](https://forum.kirupa.com/t/noobie-variable-questions/119310/4 "2004-08-14T08:18:00Z")

</div>

whoa, that answered a lot. Um… functions… one thing I don’t get about them  
function sweetness(candy){  
something happens;  
}  
what is the variable (or number) in the ( )'s? How are they used? I’ve read the tutorials on it, but still need someone to break it down ☹ sorry for the inconvenience.

---

<div class="post-metadata">

### Author: ![rysolag](https://avatars.discourse-cdn.com/v4/letter/r/ba8739/32.png) [@rysolag](https://forum.kirupa.com/u/rysolag)
#### Post date: [August 14, 2004, 8:38am UTC](https://forum.kirupa.com/t/noobie-variable-questions/119310/5 "2004-08-14T08:38:53Z")

</div>

the variables in ( )'s are called arguments. when you call the function you can pass variables to that function so the function can use them.

ex.  
[AS]  
function add(a, b)  
{  
var result = a + b;  
trace(result);  
}

add(5, 1); //output is 6  
add(1000, 5); //output is 1005  
[/AS]

functions can also return variables, heres a variation of the above add() function:

[AS]  
function add(a, b)  
{  
var result = a + b;  
return result;  
}

var mySum = add(1, 2);  
trace(mySum); //output is 3  
[/AS]

---

<div class="post-metadata">

### Author: ![LunarTears](https://avatars.discourse-cdn.com/v4/letter/l/4bbf92/32.png) [@LunarTears](https://forum.kirupa.com/u/LunarTears)
#### Post date: [August 14, 2004, 12:01pm UTC](https://forum.kirupa.com/t/noobie-variable-questions/119310/6 "2004-08-14T12:01:40Z")

</div>

so I could do have an event change that arguement and have the function work differently?

function count(num){  
var counted = num;  
trace (num)  
}

on(release){  
num += 1;  
}

like that?

---

<div class="post-metadata">

### Author: ![Prophet](https://avatars.discourse-cdn.com/v4/letter/p/838e76/32.png) [@Prophet](https://forum.kirupa.com/u/Prophet)
#### Post date: [August 14, 2004, 12:29pm UTC](https://forum.kirupa.com/t/noobie-variable-questions/119310/7 "2004-08-14T12:29:43Z")

</div>

yer… so long as u dont forget to call the function 😉 lol

Prophet.

---

<div class="post-metadata">

### Author: ![LunarTears](https://avatars.discourse-cdn.com/v4/letter/l/4bbf92/32.png) [@LunarTears](https://forum.kirupa.com/u/LunarTears)
#### Post date: [August 14, 2004, 3:24pm UTC](https://forum.kirupa.com/t/noobie-variable-questions/119310/8 "2004-08-14T15:24:29Z")

</div>

how do I do that? just type it in?

function count();  
?

another question.

if i had a thing like this:

stop();  
apple = red;  
lime = green;

would it play the whole script first? or would the bottom part be played when it starts playing again?

---

<div class="post-metadata">

### Author: ![LunarTears](https://avatars.discourse-cdn.com/v4/letter/l/4bbf92/32.png) [@LunarTears](https://forum.kirupa.com/u/LunarTears)
#### Post date: [August 14, 2004, 3:35pm UTC](https://forum.kirupa.com/t/noobie-variable-questions/119310/9 "2004-08-14T15:35:17Z")

</div>

[QUOTE=LunarTears]how do I do that? just type it in?

function count();  
?

---

<div class="post-metadata">

### Author: ![rysolag](https://avatars.discourse-cdn.com/v4/letter/r/ba8739/32.png) [@rysolag](https://forum.kirupa.com/u/rysolag)
#### Post date: [August 14, 2004, 10:28pm UTC](https://forum.kirupa.com/t/noobie-variable-questions/119310/10 "2004-08-14T22:28:51Z")

</div>

for your stop() question: everything will be executed no matter where the stop function is. it stops the frames from proceeding not the line execution number.

for your function count() question:

[AS]  
function count(num)  
{  
var counted = num;  
trace(counted);  
}

var test = 1;  
count(test); // 1  
test++;  
count(test); // 2  
test++;  
count(test); // 3  
test += 1000;  
count(test); // 1003  
[/AS]

---

<div class="post-metadata">

### Author: ![LunarTears](https://avatars.discourse-cdn.com/v4/letter/l/4bbf92/32.png) [@LunarTears](https://forum.kirupa.com/u/LunarTears)
#### Post date: [August 16, 2004, 1:18am UTC](https://forum.kirupa.com/t/noobie-variable-questions/119310/11 "2004-08-16T01:18:34Z")

</div>

i dont understand that script at all ☹ maybe it’s the horrible migrane i’m having… I need a coke ☹

---

<div class="post-metadata">

### Author: ![Prophet](https://avatars.discourse-cdn.com/v4/letter/p/838e76/32.png) [@Prophet](https://forum.kirupa.com/u/Prophet)
#### Post date: [August 16, 2004, 6:38pm UTC](https://forum.kirupa.com/t/noobie-variable-questions/119310/12 "2004-08-16T18:38:21Z")

</div>

btw to call a function you dont include the word function - it might be on a diff path so it could be

```auto
code()

```

or

```auto
_root.mc1.code()

```

etc etc

Prophet.

---

<div class="post-metadata">

### Author: ![LunarTears](https://avatars.discourse-cdn.com/v4/letter/l/4bbf92/32.png) [@LunarTears](https://forum.kirupa.com/u/LunarTears)
#### Post date: [August 17, 2004, 8:54am UTC](https://forum.kirupa.com/t/noobie-variable-questions/119310/13 "2004-08-17T08:54:08Z")

</div>

ok, i have this here function…

l\_aboutme.onRelease = function(){  
aboutme\_anime.play();  
}

how do i call to it!?!?!

---

<div class="post-metadata">

### Author: ![Prophet](https://avatars.discourse-cdn.com/v4/letter/p/838e76/32.png) [@Prophet](https://forum.kirupa.com/u/Prophet)
#### Post date: [August 17, 2004, 5:58pm UTC](https://forum.kirupa.com/t/noobie-variable-questions/119310/14 "2004-08-17T17:58:03Z")

</div>

you cant.  
at least not in that format.  
you need to give a function a name if you intend to call it more than once…, ie.

```auto
function about(){
aboutme_anime.play()
}

```

then if you want to call it you simply write

```auto
about()

```

if it is on the same directory… ie. if its in a movie clip or the code you are trying to call the function from is in a movieclip you would need a path reference like _\_parent.about()_  
if you want to apply it to the button\* l\_aboutme\* you use this (once your function is declared such as above, on the same path):

```auto
l_aboutme.onRelease = function(){
	about()
}

```

Prophet.

---

<div class="post-metadata">

### Author: ![rysolag](https://avatars.discourse-cdn.com/v4/letter/r/ba8739/32.png) [@rysolag](https://forum.kirupa.com/u/rysolag)
#### Post date: [August 17, 2004, 8:46pm UTC](https://forum.kirupa.com/t/noobie-variable-questions/119310/15 "2004-08-17T20:46:43Z")

</div>

or

[AS]  
l\_aboutme.onRelease = about;  
[/AS]

---

<div class="post-metadata">

### Author: ![Prophet](https://avatars.discourse-cdn.com/v4/letter/p/838e76/32.png) [@Prophet](https://forum.kirupa.com/u/Prophet)
#### Post date: [August 17, 2004, 8:56pm UTC](https://forum.kirupa.com/t/noobie-variable-questions/119310/16 "2004-08-17T20:56:12Z")

</div>

yer for sum reason i kept tryin _onRelease = about()_ an wondered y it dint work so i just did it the long way lol

Prophet.
