Re: [Flashcoders] Scope of variables declared in for loop

2008-12-23 Thread Juan Pablo Califano
Yes, in AS 2 and AS 3 you have a local scope and global scope and that's it. You can't create new "nested" scopes using braces or other means. The variable declaration will be moved to the top of the function by the compiler (I think this is called "hoisting"). So if you write: function test(para

Re: [Flashcoders] Scope of variables declared in for loop

2008-12-23 Thread allandt bik-elliott (thefieldcomic.com)
a method / function or a class / frame On Tue, Dec 23, 2008 at 10:37 AM, Alexander Farber < alexander.far...@gmail.com> wrote: > How do you define a "code section" then? > > Regards > Alex > > On Tue, Dec 23, 2008 at 11:25 AM, Paul Andrews wrote: > > >> Is there an explanation for that? > > > >

RE: [Flashcoders] Scope of variables declared in for loop

2008-12-23 Thread Cor
Oops, forgot to declare the i properly. So again: Function doLoop1():void{ for (var i:int = 0; i < 10; i++) { trace('1st loop: ' + i); } } Function doLoop2():void{ for (var i:int = 0; i < 10; i++) { trace('2nd loop: ' + i); } } If you would like the result outside of the func

RE: [Flashcoders] Scope of variables declared in for loop

2008-12-23 Thread Cor
oders List Subject: Re: [Flashcoders] Scope of variables declared in for loop Hello, yes in AS3, but I think AS2 had the same irritating issue. Sure you can put var i:int above. But in many other languages (like C++, Java, Perl) you write something like for (my $i = 0; $i < 10; $i++) {

Re: [Flashcoders] Scope of variables declared in for loop

2008-12-23 Thread Alexander Farber
How do you define a "code section" then? Regards Alex On Tue, Dec 23, 2008 at 11:25 AM, Paul Andrews wrote: >> Is there an explanation for that? > > Flash doesn't scope the variables to the loop block, but to the code > section. ___ Flashcoders mailin

Re: [Flashcoders] Scope of variables declared in for loop

2008-12-23 Thread Alexander Farber
Hello, yes in AS3, but I think AS2 had the same irritating issue. Sure you can put var i:int above. But in many other languages (like C++, Java, Perl) you write something like for (my $i = 0; $i < 10; $i++) { # XXX } an the scope of variable is limited to the loop only. Regards Alex On

Re: [Flashcoders] Scope of variables declared in for loop

2008-12-23 Thread Paul Andrews
- Original Message - From: "Alexander Farber" To: "Flash Coders List" Sent: Tuesday, December 23, 2008 10:02 AM Subject: [Flashcoders] Scope of variables declared in for loop Hello, has anybody else noticed, that the code like: stop(); for (var i:Number = 0; i < 10; i++) { trace('

Re: [Flashcoders] Scope of variables declared in for loop

2008-12-23 Thread ekameleon
Hello :) Your code is in AS3 ? In AS3 : var i:int ; // only one for ( i = 0; i < 10; i++) { trace('1st loop: ' + i); } for ( i = 0; i < 10; i++) { trace('2nd loop: ' + i); } The FlashPlayer 9 or 10 optimize the variables and you must implement a variable one time in the same expr