|
|
Search Tutorials
Variable Scope (cont.) Here is an extract of some code to help you understand variable scope. Notice the variable i. This is a local variable and only holds relevance within the FOR loop. Once the end of the block of code is reached the variable expires. The rest of the movie doesn't even know the variable exists. As a result the name i can be reused in other local contexts with out a name collision occuring.
function bounceMove () {
for (var i = 1; i<=nrBouncers; i++) {
if (getProperty("bounce"+i, _name) != drag) {
var x = getProperty("bounce"+i, _x);
setProperty ("bounce"+i, _x, x+bounceArray[i-1].xdir);
To declare a global variable select the setVariable action from the Actions folder in your toolbox (left window of the action panel) or the assignment operator (=). To declare local variables use the var action and inside the block of code you wish the variable to have relevance. Local variables are scoped to the block, and expire at the end of the block. Local variables not declared within a block expire at the end of their script.
|
||||||||||||||||||||||||||||||||||||||||||||||||
![]() |
|||||||||||||||||||||||||||||||||||||||||||||||||
|