Scope in ActionScript
For the record - I'm working on massive source code that was written by people who were incompetent at the time, and are no longer working here. So if it makes no sense to you why I'm having this problem and why I can't just rename the variable - trust me, it makes sense! So...
There's a variable declared in the global scope - outside of any classes. It's used in a function.
There's another function that declares a variable with the same name and uses that.
The code seems to compile with no problems - I can't actually test the functionality of it right now.
But to save me a couple of hours of testing once I can try running some examples - does anybody know if this causes undefined behavior, or if AS just uses the most local variable by default, or what?
I read in Adobe's documentation that a variable defined in a function is actually useable before the declaration and outside the function. WEIRD! So I'm a little lost about scope...
From reading http://livedocs.adobe.com/flash/mx20...=00000785.html
I'm pretty convinced that unless you specify _global, it is the local variant that you get.
ActionScript should follow ECMAScript scoping rules. Thus you get the most local variable the interpreter can find.
There's no such thing as undefined behaviour in ActionScript.
Aww... I miss undefined behavior!
Well thanks for the answers! The links posted by dwks are exactly the ones confusing me - because they almost seem to conflict with a book I have published by Adobe...