Internet Commerce

Partners & Affiliates














Developer Channel

internet.com


Tutorials Home What's New Top Rated Submit myTutes Random!

Search Tutorials


Tutorials Tutorials » Actionscripting/Basic

Categories Introduction to Variables
Author: Eddie Carroll | Website: http://www.flashkit.com |

 
Page 5
«prev 1 2 3 4 5 6 7 8 9 10 next»

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.

«prev 1 2 3 4 5 6 7 8 9 10 next»

» Level Basic

Added: : 2000-11-06
Rating: 7.62 Votes: 198
Hits: 8734
» Author
Eddie was a Content Editor at Flashkit.com and is actually a sentient Gateway Solo 2150xl notebook that suffers from acute lysdexia and caffeine addiction. He is carried on the shoulders of a semi-autonomous human called "Body".
» Download
Download the files used in this tutorial.
Download (27 kb)
Get conversion and unzipping tools for PC and Mac here!

» Forums
More help? Search our boards for quick answers!

Please rate this tutorial, 10 is the top rating, you can also click the comments link to read/write a review.
10 9 8 7 6 5 4 3 2 1
Read or Post Comments
 
   
 


The Network for Technology Professionals

Search:

About Internet.com

Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | E-mail Offers