I guess I should have provided an example when I mentioned no block
level scoping. Try this on for size:

for (i = 0; i < 10; ++i); // Do nothing but increment i
var i:int;
trace(i);

This is totally valid code and will trace 10! ALL variable
declarations in a function, regardless of the block the variable is
declared in, are performed as the function is pushed on the stack.

Cory

On Thu, Mar 27, 2008 at 3:47 PM, jonathan howe <[EMAIL PROTECTED]> wrote:
> "I wish it did."
>
>  Maybe at least one person saying that was what I was looking for... Thanks
>  for the discussion!
>
>
>
>  On Thu, Mar 27, 2008 at 4:22 PM, Ian Thomas <[EMAIL PROTECTED]> wrote:
>
>  > AFAIK, in AS2 the Flash IDE didn't respect block level scoping, but
>  > MTASC did, which led to some confusion. That leads some people to
>  > think that AS2 as a language has block level scoping.
>  >
>  > AS3 definitely doesn't respect block scopes, and I curse every time I
>  > trip over that 'variable declared twice' issue. I wish it did.
>  >
>  > Ian
>  >
>  > On Thu, Mar 27, 2008 at 8:09 PM, Juan Pablo Califano
>  > <[EMAIL PROTECTED]> wrote:
>  > > for (var i:int = 0; i < 10; i++)
>  > >
>  > > {
>  > >   if (i == 5) break;
>  > >  }
>  > >  trace(i);
>  > >
>  > >  Mmm, have you actually tested the example? Because it does trace 5,
>  > since,
>  > >  as it was explained earlier in this thread, there is no block level
>  > scoping
>  > >  in AS 3.0. In fact, and this was mentioned too, all var declarations
>  > are
>  > >  "moved up" to be executed as the first actions run in a function's code
>  > (I
>  > >  believe that was called hoisting, but I might be wrong).
>  > >
>  > >  Cheers
>  > >  Juan Pablo Califano
>  > >
>  > >  2008/3/27, Steven Sacks <[EMAIL PROTECTED]>:
>  > >
>  > >
>  > > >
>  > >  > function doSomething
>  > >  > > {
>  > >  > >   var i:int;
>  > >  > >   for(i=0;i++;i<10)
>  > >  > >   {
>  > >  > >   }
>  > >  > > }
>  > >  > >
>  > >  > > Is functionally identical to this:
>  > >  > >
>  > >  > > function doSomething
>  > >  > > {
>  > >  > >   for(var i:int =0;i++;i<10)
>  > >  > >   {
>  > >  > >   }
>  > >  > > }
>  > >  >
>  > >  > Wrong.  It's not.
>  > >  >
>  > >  > In the latter example, i is not available after the loop.  In the
>  > first
>  > >  > example, it is.
>  > >  >
>  > >  > var i:int;
>  > >  > for (i = 0; i < 10; i++)
>  > >  > {
>  > >  >   if (i == 5) break;
>  > >  > }
>  > >  > trace(i);
>  > >  > -- 5
>  > >  >
>  > >  > There are a multitude of uses for this, and I do it all the
>  > >  > time.  Additionally, I read somewhere many moons ago (back in my
>  > FLASM days)
>  > >  > that declaring variables outside a for loop is less bytecode and uses
>  > less
>  > >  > memory.  I don't believe that applies to the counter declaration, but
>  > I do
>  > >  > know it applies to the comparison as well as vars declared inside the
>  > for
>  > >  > loop.  However, this level of optimization is only useful in a
>  > practical way
>  > >  > on mobile and some games.
>  > >  >
>  > >  > _______________________________________________
>  > >  > Flashcoders mailing list
>  > >  > Flashcoders@chattyfig.figleaf.com
>  > >  > http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
>  > >  >
>  > >  _______________________________________________
>  > >  Flashcoders mailing list
>  > >  Flashcoders@chattyfig.figleaf.com
>  > >  http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
>  > >
>  > _______________________________________________
>  > Flashcoders mailing list
>  > Flashcoders@chattyfig.figleaf.com
>  > http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
>  >
>
>
>
>
> --
>  -jonathan howe :: 404.434.2321 :: 180 High St Apt 26 Portland, ME 04101
>  _______________________________________________
>
>
> Flashcoders mailing list
>  Flashcoders@chattyfig.figleaf.com
>  http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
>



-- 
Cory Petosky : Lead Developer : PUNY
1618 Central Ave NE Suite 130
Minneapolis, MN 55413
Office: 612.216.3924
Mobile: 240.422.9652
Fax: 612.605.9216
http://www.punyentertainment.com
_______________________________________________
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Reply via email to