ActionScript doesn't have (and has never had) block-scoped variables. When you declare a local variable anywhere in a method, it is as if you had declared it at the top, and it is accessible anywhere in the method. Therefore having two declarations is redundant. The new warning is trying to make people aware of this (probably unexpected) behavior. In your case of two for-loops, the coding standards we use in the framework classes would do it like this:

 

var i:int;

 

for (i = 0; i < 10; i++)

{

    ...

}

 

for (i = 0; i < 10; i++)

{

    ...

}

 

- Gordon

 


From: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] On Behalf Of Dirk Eismann
Sent: Wednesday, June 28, 2006 2:46 AM
To: flexcoders@yahoogroups.com
Subject: RE: [flexcoders] Duplicate variable definition

 

yes.

 


From: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] On Behalf Of Jonas Windey
Sent: Wednesday, June 28, 2006 11:29 AM
To: flexcoders@yahoogroups.com
Subject: [flexcoders] Duplicate variable definition

Hi,

 

In flex 2 b3, it was allowed to do this:

 

rivate function fcnTest():void

{

for (var i:Number=0;i< 10;i++){

            //do sthing                                            

}

for (var i:Number=0;i< 10;i++){

            //do something more                                         

}

}

 

In 2.0 final, I get Duplicate variable definition.

 

Should I only declare it once before every loop?

 

Jonas

__._,_.___

--
Flexcoders Mailing List
FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.com





SPONSORED LINKS
Web site design development Computer software development Software design and development
Macromedia flex Software development best practice


YAHOO! GROUPS LINKS




__,_._,___

Reply via email to