Flash8-global variables and local variables

Source: Internet
Author: User

Variables in Flash 8 can be used without being defined. This will cause a mixture of global variables and local variables. errors may occur when used.

 

A global variable is not only a variable defined outside the function, but is also a global variable if the variable used in the function is not defined.

A local variable is a variable defined in a function. before using this local variable, you must use var. Otherwise, this variable is a global variable.

 

Assume that the followingCode:

Function Test(){For(I = 0; I <10; I ++ ){}}Test();Trace(I );

Variable I is used in the function, but is not defined, then I is a global variable, then trace (I) is shown as I = 10.

However, if the function has var I, I is a local variable, and trace (I) is undefined.

 

Conclusion,If you want to use a local variable, you must add var before the variable; otherwise, it is a global variable..

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.