Ah, this is a fun lesson: unlike C, C++, or any “real” programming language, variables defined inside a block (ie, surrounded by curly braces) are not defined in their own scope. Or, another way of saying it is a function only has a single scope, and any variable defined in any block in that function is considered to be in the same scope. Or perhaps an even better way of describing it is with an example. in C++, the following code would fail to compile:
{ int a = 0; } ++a; // 'a' isn't defined here
However, in ActionScript, this code compiles just fine:
{ var a:int = 0; } ++a; // 'a' is defined in the parent scope
Madness!