Whats the difference with declaring variables in the following manner:
i = 0;
and
var i = 0;
Regards,
Viru.
Whats the difference with declaring variables in the following manner:
i = 0;
and
var i = 0;
Regards,
Viru.
There isn’t… at least that’s what I think! I never use var!
well… it does have one difference. If you use it in a function:
function addOne(){
var i;
i+=1;
return i;
}
//Once the function finishes, i is destroyed. This is what the var keyword does in a function.
function addOne2(){
i+=1;
return i;
}
//because we omitted var, i is not destroyed:
for(var j = 0;j < 3;j++){
trace(addOne2());
}
//outputs 123.
for(var j = 0;j < 3;j++){
trace(addOne());
}
//outputs 111, as i is always destroyed
Other than that, it’s just good form and helps when you move on to C or Java.
Yeah i do Java too.
It says in the actionscript dictionary that it makes the variable local when var is used. Makes sense, i just wondered thats all.
Thanks,
Viru.
local to function calls. Theres no difference in using var or not on the timeline.
There is, but a very slight one. With var you have to wait a frame before you can access it from another place (like another mc), if you don’t use var you can access it straight away.
There’s something in the AS tricks about that and [m], are you sure about what you’re saying? It sounds strange :-\ How would you access that local variable from another movieclip?? Can you give an example?
:: Copyright KIRUPA 2024 //--