Noobie variable questions

I can’t figure out these variables in whatever timelines :frowning:
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 :frowning:
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?

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.

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

play()

:wink:

Prophet.

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 :frowning: sorry for the inconvenience.

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]

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?

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

Prophet.

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?

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

function count();
?

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]

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

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

code()

or

_root.mc1.code()

etc etc

Prophet.

ok, i have this here function…

l_aboutme.onRelease = function(){
aboutme_anime.play();
}

how do i call to it!?!?!

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.

function about(){
aboutme_anime.play()
}

then if you want to call it you simply write

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):

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

Prophet.

or

[AS]
l_aboutme.onRelease = about;
[/AS]

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.