It's valid both in a frame script in an IDE and in an AS3 class
compiled via mxmlc. I suspect it's also valid in an mx:script block,
but I didn't bother testing.
Actually give it a try before telling me it doesn't work. :)
On Thu, Mar 27, 2008 at 6:59 PM, Steven Sacks [EMAIL PROTECTED] wrote:
Try this:
for(var i:int; i10; i++) {
//some crap here
}
On Mon, Mar 24, 2008 at 8:49 PM, Kerry Thompson [EMAIL PROTECTED]
wrote:
jonathan howe wrote:
Hmm... it is within a class... and that's when I'm getting the warnings.
Or
did you mean just in general to reiterate that
I mean inserting var i:int instead of declaring it outside the loop.
On Thu, Mar 27, 2008 at 3:26 PM, Omar Fouad [EMAIL PROTECTED] wrote:
Try this:
for(var i:int; i10; i++) {
//some crap here
}
On Mon, Mar 24, 2008 at 8:49 PM, Kerry Thompson [EMAIL PROTECTED]
wrote:
jonathan
function doSomething
{
var i:int;
for(i=0;i++;i10)
{
}
}
Is functionally identical to this:
function doSomething
{
for(var i:int =0;i++;i10)
{
}
}
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;
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
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
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
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
Valid where? If that's in a class function and i is not a class
variable, then the compiler will complain that you're using an
undeclared variable.
Cory Petosky wrote:
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;
Using it youre way is possible when you do it within a function or class
because then they are private by default
Other you could use it this way
Example 1:
for (var i:int = 0; i someArray.length; i ++) {
// do something cool
}
for (i = 0; i someOtherArray.length; i ++) {
// do
Hmm... it is within a class... and that's when I'm getting the warnings. Or
did you mean just in general to reiterate that variables are locally scoped
to functions and classes and not to for loops?
I should have mentioned in my subject that this is AS3. So far everyone's
alternatives and
jonathan howe wrote:
Hmm... it is within a class... and that's when I'm getting the warnings.
Or
did you mean just in general to reiterate that variables are locally
scoped
to functions and classes and not to for loops?
If you declare a variable within a function, its scope is limited to that
That's easy.only after busting my asss for an hour figuring it out..
...Variables are only local to the function
Jonathan try using j in your second for statementnot the letter i twice
Hope that helps...
Sent via BlackBerry from T-Mobile
-Original Message-
From: jonathan howe
13 matches
Mail list logo