Re: [Flashcoders] Variable scope with asynchronous SQL connection
Thanks Ross, I was rewriting things along the lines of your example after reading Henrik's reply. On 4/20/11 2:53 PM, "Ross Sclafani" wrote: the problem you may run into if you call in a loop is overwriting the object property. i would implement a queue: /// private var statementQueue:Vector. = new Vector.(); public function getDayOfDrill() : void { var sql:SQLStatement = new SQLStatement(); sql.sqlConnection = _sqlConnection; sql.text = "SELECT dayOfDrill FROM time"; sql.addEventListener(SQLEvent.RESULT, getDayOfDrillResultHandler, false, 0, true); statementQueue.push(sql); sql.execute(); } private function getDayOfDrillResultHandler(e:SQLEvent) : void { var evt:FDataEvent = new FDataEvent(FDataEvent.GET_DAY_OF_DRILL); evt.param = e.target.data[0]; dispatchEvent(evt); statementQueue.splice(statementQueue.indexOf(e.target,1); } // On Apr 20, 2011, at 3:43 PM, Henrik Andersson wrote: > Mattheis, Erik (MIN-WSW) skriver: >> 1. The SQLConnection is asynchronous. Is there a possibility the function >> variable "sql" would get garbage collected before the event handler fires? > > It is a local variable. Yes, it is up for garbage collection the instant the > function returns. So if the event happens after that (as you said it will) > then the garbage collection may happen before that. > ___ > 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 _ _ _ Erik Mattheis | Weber Shandwick P: (952) 346.6610 M: (612) 377.2272 ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Re: [Flashcoders] Variable scope with asynchronous SQL connection
the problem you may run into if you call in a loop is overwriting the object property. i would implement a queue: /// private var statementQueue:Vector. = new Vector.(); public function getDayOfDrill() : void { var sql:SQLStatement = new SQLStatement(); sql.sqlConnection = _sqlConnection; sql.text = "SELECT dayOfDrill FROM time"; sql.addEventListener(SQLEvent.RESULT, getDayOfDrillResultHandler, false, 0, true); statementQueue.push(sql); sql.execute(); } private function getDayOfDrillResultHandler(e:SQLEvent) : void { var evt:FDataEvent = new FDataEvent(FDataEvent.GET_DAY_OF_DRILL); evt.param = e.target.data[0]; dispatchEvent(evt); statementQueue.splice(statementQueue.indexOf(e.target,1); } // On Apr 20, 2011, at 3:43 PM, Henrik Andersson wrote: > Mattheis, Erik (MIN-WSW) skriver: >> 1. The SQLConnection is asynchronous. Is there a possibility the function >> variable "sql" would get garbage collected before the event handler fires? > > It is a local variable. Yes, it is up for garbage collection the instant the > function returns. So if the event happens after that (as you said it will) > then the garbage collection may happen before that. > ___ > 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
Re: [Flashcoders] Variable scope with asynchronous SQL connection
Mattheis, Erik (MIN-WSW) skriver: 1. The SQLConnection is asynchronous. Is there a possibility the function variable "sql" would get garbage collected before the event handler fires? It is a local variable. Yes, it is up for garbage collection the instant the function returns. So if the event happens after that (as you said it will) then the garbage collection may happen before that. ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Re: [Flashcoders] Variable scope within for loops: reusing iteratorvariables
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 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: > 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; ++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. > > > > > > ___ > 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
Re: [Flashcoders] Variable scope within for loops: reusingiteratorvariables
Oh. Oh dear. *sigh* Well, I do confess that there's nostalgic joy at the prospect of being able to type: let x=7 (which I don't think I've done since I last used BASIC back in I don't know when. Around the 1800s, wasn't it?) But I'm not sure I'd introduce a whole new keyword for it. I'd probably make var scope work 'as commonly expected' - i.e. block-level - in ES4 and throw in a compiler switch to turn it off for backwards compatibility. But I guess that could be 'as commonly expected - by me'. ;-) Ian On Thu, Mar 27, 2008 at 11:51 PM, Francis Cheng <[EMAIL PROTECTED]> wrote: > Ian, help is on the way, the ECMAScript 4th edition draft specification > contains a new keyword, "let", that can be used in place of "var" to > provide block-level scoping. Details for the curious: > > http://wiki.ecmascript.org/doku.php?id=proposals:block_expressions > > Francis Cheng | Senior Technical Writer | Adobe Systems, Inc. > http://blogs.adobe.com/fcheng > ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Re: [Flashcoders] Variable scope within for loops: reusing iteratorvariables
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; ++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. ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
RE: [Flashcoders] Variable scope within for loops: reusingiteratorvariables
Ian, help is on the way, the ECMAScript 4th edition draft specification contains a new keyword, "let", that can be used in place of "var" to provide block-level scoping. Details for the curious: http://wiki.ecmascript.org/doku.php?id=proposals:block_expressions Francis Cheng | Senior Technical Writer | Adobe Systems, Inc. http://blogs.adobe.com/fcheng -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Ian Thomas Sent: Thursday, March 27, 2008 1:23 PM To: Flash Coders List Subject: Re: [Flashcoders] Variable scope within for loops: reusingiteratorvariables 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 ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Re: [Flashcoders] Variable scope within for loops: reusing iteratorvariables
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
Re: [Flashcoders] Variable scope within for loops: reusing iteratorvariables
"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
Re: [Flashcoders] Variable scope within for loops: reusing iteratorvariables
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
Re: [Flashcoders] Variable scope within for loops: reusing iteratorvariables
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
Re: [Flashcoders] Variable scope within for loops: reusing iteratorvariables
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
Re: [Flashcoders] Variable scope within for loops: reusing iteratorvariables
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; i<10; 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 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 > > function. It really doesn't relate to where in the function you use it > > (or > > declare it). In my example, this: > > > > 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) > > { > > } > > } > > > > You're correct that AS3 is more strict about these sorts of things than > > AS2. > > AS2 was really just syntactic sugar for AS1, and wasn't strict at all. > > > > Cordially, > > > > Kerry Thompson > > > > > > ___ > > Flashcoders mailing list > > Flashcoders@chattyfig.figleaf.com > > http://chattyfig.figleaf.com/mailman/listinfo/flashcoders > > > > > > -- > Omar M. Fouad - Digital Emotions > http://www.omarfouad.net > > This e-mail and any attachment is for authorised use by the intended > recipient(s) only. It may contain proprietary material, confidential > information and/or be subject to legal privilege. It should not be copied, > disclosed to, retained or used by, any other party. If you are not an > intended recipient then please promptly delete this e-mail and any > attachment and all copies and inform the sender. Thank you. -- Omar M. Fouad - Digital Emotions http://www.omarfouad.net This e-mail and any attachment is for authorised use by the intended recipient(s) only. It may contain proprietary material, confidential information and/or be subject to legal privilege. It should not be copied, disclosed to, retained or used by, any other party. If you are not an intended recipient then please promptly delete this e-mail and any attachment and all copies and inform the sender. Thank you. ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Re: [Flashcoders] Variable scope within for loops: reusing iteratorvariables
Try this: for(var i:int; i<10; 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 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 > function. It really doesn't relate to where in the function you use it (or > declare it). In my example, this: > > 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) > { > } > } > > You're correct that AS3 is more strict about these sorts of things than > AS2. > AS2 was really just syntactic sugar for AS1, and wasn't strict at all. > > Cordially, > > Kerry Thompson > > > ___ > Flashcoders mailing list > Flashcoders@chattyfig.figleaf.com > http://chattyfig.figleaf.com/mailman/listinfo/flashcoders > -- Omar M. Fouad - Digital Emotions http://www.omarfouad.net This e-mail and any attachment is for authorised use by the intended recipient(s) only. It may contain proprietary material, confidential information and/or be subject to legal privilege. It should not be copied, disclosed to, retained or used by, any other party. If you are not an intended recipient then please promptly delete this e-mail and any attachment and all copies and inform the sender. Thank you. ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
RE: [Flashcoders] Variable scope within for loops: reusing iteratorvariables
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 function. It really doesn't relate to where in the function you use it (or declare it). In my example, this: 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) { } } You're correct that AS3 is more strict about these sorts of things than AS2. AS2 was really just syntactic sugar for AS1, and wasn't strict at all. Cordially, Kerry Thompson ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Re: [Flashcoders] Variable scope within for loops: reusing iterator variables
besides, the compiler only warns you that you're about the overwrite the variable, by re-assigning it. In case of 2 loops(where the variable is only used within the loop), it doesn't have any real consequences. On Mon, Mar 24, 2008 at 4:56 PM, Cory Petosky <[EMAIL PROTECTED]> wrote: > Jonathon: > > In any other language, the scope would be as you describe. AS3 doesn't > have block-level scoping -- the most local scope is always the > function. Declaring a variable anywhere but the first line of a > function is a lie -- the VM declares all variables as the first set of > operations after pushing the function call on the stack. > > On Mon, Mar 24, 2008 at 7:36 AM, Andrew Sinning <[EMAIL PROTECTED]> > wrote: > > You are correct Jonathan, but loop blocks are delimited by brackets, so > > the "for ( ... )" declaration is outside of the loop block. > > > > > > jonathan howe wrote: > > > I had always thought that the scope of variables declared in the > > > initialization part of the for loop were local to the loop block > > > > > > > > ___ > > 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 > -- M.A. van't Kruis http://www.malatze.nl/ ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Re: [Flashcoders] Variable scope within for loops: reusing iterator variables
Jonathon: In any other language, the scope would be as you describe. AS3 doesn't have block-level scoping -- the most local scope is always the function. Declaring a variable anywhere but the first line of a function is a lie -- the VM declares all variables as the first set of operations after pushing the function call on the stack. On Mon, Mar 24, 2008 at 7:36 AM, Andrew Sinning <[EMAIL PROTECTED]> wrote: > You are correct Jonathan, but loop blocks are delimited by brackets, so > the "for ( ... )" declaration is outside of the loop block. > > > jonathan howe wrote: > > I had always thought that the scope of variables declared in the > > initialization part of the for loop were local to the loop block > > > > ___ > 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
Re: [Flashcoders] Variable scope within for loops: reusing iterator variables
You are correct Jonathan, but loop blocks are delimited by brackets, so the "for ( ... )" declaration is outside of the loop block. jonathan howe wrote: I had always thought that the scope of variables declared in the initialization part of the for loop were local to the loop block ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
RE: [Flashcoders] Variable scope within for loops:reusingiteratorvariables
You should ask the creators of AS3 that. Its their choice -Oorspronkelijk bericht- Van: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Namens jonathan howe Verzonden: maandag 24 maart 2008 9:35 Aan: Flash Coders List Onderwerp: Re: [Flashcoders] Variable scope within for loops:reusingiteratorvariables I totally agree with your explanation, and the part that I am being pouty about is: "Why isn't the variable's scope confined to the loop?" a la: for (var i:int = 0; i < limit; i ++) { // variable is instantiated // scope of variable } // variable is discarded instead of it being what several of you have described. -jonathan On Mon, Mar 24, 2008 at 4:22 AM, Cor <[EMAIL PROTECTED]> wrote: > Indeed, I was talking about AS3 too. > > For reasoning: Its like the real world -> every object is UNIQUE, > therefor there can only exist ONE of it. > You can make copies (instances) but they will have there own unique name. > You can use it as much as you like but you can't CREATE the same > object (within its scope) again. > > Does this explain it for you? > > -Oorspronkelijk bericht- > Van: [EMAIL PROTECTED] > [mailto:[EMAIL PROTECTED] Namens jonathan > howe > Verzonden: maandag 24 maart 2008 9:14 > Aan: Flash Coders List > Onderwerp: Re: [Flashcoders] Variable scope within for loops: > reusingiteratorvariables > > 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 explanations make sense, I am just curious > now as to the reasoning. Either this is a change from AS2 -> AS3 or > since AS2 wasn't as strict, it let me do it before. Maybe the > explanation lies in the ECMA guidelines somewhere. Anyway, thanks for the discussion, gang. > > -jonathan > > > On Mon, Mar 24, 2008 at 3:53 AM, Cor <[EMAIL PROTECTED]> wrote: > > > 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 something even cooler > > } > > > > --- > > Example 2: > > var i:int; //or uint if I is never negative > > > > for (i = 0; i < someArray.length; i ++) { > > // do something cool > > } > > > > for (i = 0; i < someOtherArray.length; i ++) { > > // do something even cooler > > } > > > > No virus found in this outgoing message. > > Checked by AVG. > > Version: 7.5.519 / Virus Database: 269.21.8/1340 - Release Date: > > 23-3-2008 18:50 > > > > > > ___ > > 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 > > > -- > No virus found in this incoming message. > Checked by AVG. > Version: 7.5.519 / Virus Database: 269.21.8/1340 - Release Date: > 23-3-2008 18:50 > > No virus found in this incoming message. > Checked by AVG. > Version: 7.5.519 / Virus Database: 269.21.8/1340 - Release Date: > 23-3-2008 18:50 > > > No virus found in this outgoing message. > Checked by AVG. > Version: 7.5.519 / Virus Database: 269.21.8/1340 - Release Date: > 23-3-2008 18:50 > > > ___ > 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 -- No virus found in this incoming message. Checked by AVG. Version: 7.5.519 / Virus Database: 269.21.8/1340 - Release Date: 23-3-2008 18:50 No virus found in this incoming message. Checked by AVG. Version: 7.5.519 / Virus Database: 269.21.8/1340 - Release Date: 23-3-2008 18:50 No virus found in this outgoing message. Checked by AVG. Version: 7.5.519 / Virus Database: 269.21.8/1340 - Release Date: 23-3-2008 18:50 ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Re: [Flashcoders] Variable scope within for loops: reusingiteratorvariables
I totally agree with your explanation, and the part that I am being pouty about is: "Why isn't the variable's scope confined to the loop?" a la: for (var i:int = 0; i < limit; i ++) { // variable is instantiated // scope of variable } // variable is discarded instead of it being what several of you have described. -jonathan On Mon, Mar 24, 2008 at 4:22 AM, Cor <[EMAIL PROTECTED]> wrote: > Indeed, I was talking about AS3 too. > > For reasoning: Its like the real world -> every object is UNIQUE, therefor > there can only exist ONE of it. > You can make copies (instances) but they will have there own unique name. > You can use it as much as you like but you can't CREATE the same object > (within its scope) again. > > Does this explain it for you? > > -Oorspronkelijk bericht- > Van: [EMAIL PROTECTED] > [mailto:[EMAIL PROTECTED] Namens jonathan howe > Verzonden: maandag 24 maart 2008 9:14 > Aan: Flash Coders List > Onderwerp: Re: [Flashcoders] Variable scope within for loops: > reusingiteratorvariables > > 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 explanations make sense, I am just curious now as to the > reasoning. Either this is a change from AS2 -> AS3 or since AS2 wasn't as > strict, it let me do it before. Maybe the explanation lies in the ECMA > guidelines somewhere. Anyway, thanks for the discussion, gang. > > -jonathan > > > On Mon, Mar 24, 2008 at 3:53 AM, Cor <[EMAIL PROTECTED]> wrote: > > > 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 something even cooler > > } > > > > --- > > Example 2: > > var i:int; //or uint if I is never negative > > > > for (i = 0; i < someArray.length; i ++) { > > // do something cool > > } > > > > for (i = 0; i < someOtherArray.length; i ++) { > > // do something even cooler > > } > > > > No virus found in this outgoing message. > > Checked by AVG. > > Version: 7.5.519 / Virus Database: 269.21.8/1340 - Release Date: > > 23-3-2008 18:50 > > > > > > ___ > > 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 > > > -- > No virus found in this incoming message. > Checked by AVG. > Version: 7.5.519 / Virus Database: 269.21.8/1340 - Release Date: 23-3-2008 > 18:50 > > No virus found in this incoming message. > Checked by AVG. > Version: 7.5.519 / Virus Database: 269.21.8/1340 - Release Date: 23-3-2008 > 18:50 > > > No virus found in this outgoing message. > Checked by AVG. > Version: 7.5.519 / Virus Database: 269.21.8/1340 - Release Date: 23-3-2008 > 18:50 > > > ___ > 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
RE: [Flashcoders] Variable scope within for loops: reusingiteratorvariables
Indeed, I was talking about AS3 too. For reasoning: Its like the real world -> every object is UNIQUE, therefor there can only exist ONE of it. You can make copies (instances) but they will have there own unique name. You can use it as much as you like but you can't CREATE the same object (within its scope) again. Does this explain it for you? -Oorspronkelijk bericht- Van: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Namens jonathan howe Verzonden: maandag 24 maart 2008 9:14 Aan: Flash Coders List Onderwerp: Re: [Flashcoders] Variable scope within for loops: reusingiteratorvariables 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 explanations make sense, I am just curious now as to the reasoning. Either this is a change from AS2 -> AS3 or since AS2 wasn't as strict, it let me do it before. Maybe the explanation lies in the ECMA guidelines somewhere. Anyway, thanks for the discussion, gang. -jonathan On Mon, Mar 24, 2008 at 3:53 AM, Cor <[EMAIL PROTECTED]> wrote: > 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 something even cooler > } > > --- > Example 2: > var i:int; //or uint if I is never negative > > for (i = 0; i < someArray.length; i ++) { > // do something cool > } > > for (i = 0; i < someOtherArray.length; i ++) { > // do something even cooler > } > > No virus found in this outgoing message. > Checked by AVG. > Version: 7.5.519 / Virus Database: 269.21.8/1340 - Release Date: > 23-3-2008 18:50 > > > ___ > 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 -- No virus found in this incoming message. Checked by AVG. Version: 7.5.519 / Virus Database: 269.21.8/1340 - Release Date: 23-3-2008 18:50 No virus found in this incoming message. Checked by AVG. Version: 7.5.519 / Virus Database: 269.21.8/1340 - Release Date: 23-3-2008 18:50 No virus found in this outgoing message. Checked by AVG. Version: 7.5.519 / Virus Database: 269.21.8/1340 - Release Date: 23-3-2008 18:50 ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Re: [Flashcoders] Variable scope within for loops: reusing iteratorvariables
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 explanations make sense, I am just curious now as to the reasoning. Either this is a change from AS2 -> AS3 or since AS2 wasn't as strict, it let me do it before. Maybe the explanation lies in the ECMA guidelines somewhere. Anyway, thanks for the discussion, gang. -jonathan On Mon, Mar 24, 2008 at 3:53 AM, Cor <[EMAIL PROTECTED]> wrote: > 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 something even cooler > } > > --- > Example 2: > var i:int; //or uint if I is never negative > > for (i = 0; i < someArray.length; i ++) { > // do something cool > } > > for (i = 0; i < someOtherArray.length; i ++) { > // do something even cooler > } > > No virus found in this outgoing message. > Checked by AVG. > Version: 7.5.519 / Virus Database: 269.21.8/1340 - Release Date: 23-3-2008 > 18:50 > > > ___ > 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
RE: [Flashcoders] Variable scope within for loops: reusing iteratorvariables
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 something even cooler } --- Example 2: var i:int; //or uint if I is never negative for (i = 0; i < someArray.length; i ++) { // do something cool } for (i = 0; i < someOtherArray.length; i ++) { // do something even cooler } No virus found in this outgoing message. Checked by AVG. Version: 7.5.519 / Virus Database: 269.21.8/1340 - Release Date: 23-3-2008 18:50 ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Re: [Flashcoders] Variable scope within for loops: reusing iteratorvariables
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" <[EMAIL PROTECTED]> Date: Sun, 23 Mar 2008 20:00:41 To:flashcoders@chattyfig.figleaf.com Subject: [Flashcoders] Variable scope within for loops: reusing iterator variables I was hoping someone could explain why I get "Warning: 3596: Duplicate variable definition." warnings when I reuse an iterator variable. Example: for (var i:int = 0; i < someArray.length; i ++) { // do something cool } for (var i:int = 0; i < someOtherArray.length; i ++) { // do something even cooler } I had always thought that the scope of variables declared in the initialization part of the for loop were local to the loop block, not the block containing the loop. So I guess that is not true... does this mean the second time I use the loop I have to omit the declaration? Or is there a keyword I can use to keep the instantiation local to the for block? Seems like it would be clunky if I was cutting and pasting blocks of code in different orders, I'd have to keep track of who was the first for loop of any code block (an admittedly minor annoyance, since I don't have stacks and stacks of loops, but still...) Thanks in advance, -jonathan -- -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 ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
RE: [Flashcoders] Variable scope within for loops: reusing iterator variables
jonathan howe wrote: > I was hoping someone could explain why I get "Warning: 3596: Duplicate > variable definition." warnings when I reuse an iterator variable. > Example: > > for (var i:int = 0; i < someArray.length; i ++) { > // do something cool > } > > for (var i:int = 0; i < someOtherArray.length; i ++) { > // do something even cooler > } The first time you declare the var i, it is in scope for the rest of the function, not the loop. Think of it this way: function someFunc():void { . . . var i:int; for (i = 0; i < someArray.length; i ++) { // do something cool } for (i = 0; i < someOtherArray.length; i ++) { // do something even cooler } } Make sense? Cordially, Kerry Thompson ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
RE: [Flashcoders] variable scope
Sure: I am trying to retreive kp_array in 'classB', which is in the kpLoad function. /** * ... * @author - * @version 0.1 */ import mx.utils.Delegate; class xmlHandler { public var new_array : Array; public var numKPs : Number; public var kpID_array :Array public var kp_array :Array private var kp_xml : XML; private var numGlossIDs : Number; public var numGlossTerms : Number; private var letters_array : Array; private var glIndex_array : Array; private var glTerms_array : Array; public var glDefs_array : Array; private var tmpArr1 : Array; private var tmpArr2 : Array; private var glButtActive : Array; private var gl_xml : XML; private var numRefs : Number; private var ref_xml : XML; public var refID_array : Array; private var refRef_array : Array; private var i : Number; private var j : Number; private var __index : Number; var kp_cmp:mx.controls.TextArea; public function xmlHandler(){ //Keypoints kpID_array = new Array; kp_array = new Array; kp_xml = new XML (); kp_xml.ignoreWhite = true; //Glossary letters_array = new Array; glIndex_array = new Array; glTerms_array = new Array; glDefs_array = new Array; glButtActive = new Array; tmpArr1 = new Array; tmpArr2 = new Array; gl_xml = new XML (); gl_xml.ignoreWhite = true; //References refID_array = new Array; refRef_array = new Array; ref_xml = new XML (); ref_xml.ignoreWhite = true; //Load keypoints kp_xml.load ("xml/keypoints.xml"); kp_xml.onLoad = Delegate.create (this, kpLoad); } public function kpLoad (bSuccess : Boolean) { if (bSuccess){ //trace("Keypoints loaded!"); //Sort keypoints numKPs = kp_xml.firstChild.childNodes.length; for (i = 0; i < numKPs; i ++){ kpID_array.push (kp_xml.firstChild.childNodes[i].attributes.id); kp_array.push (kp_xml.firstChild.childNodes[i].childNodes[0].nodeValue); } // //trace(kp_array); gl_xml.load ("xml/glossary.xml"); gl_xml.onLoad = Delegate.create (this, glossLoad); } else { _root.debug_txt.text = "Keypoints XML failed to load"; } } public function glossLoad (bSuccess : Boolean) { if (bSuccess){ //trace("Glossary loaded!"); //Sort glossary numGlossIDs = gl_xml.firstChild.childNodes.length; for (i = 0; i < numGlossIDs; i ++) { numGlossTerms = gl_xml.firstChild.childNodes [i].childNodes.length; glIndex_array.push (gl_xml.firstChild.childNodes [i].attributes.letter); if (numGlossTerms == 0) { glButtActive.push(0); } else { glButtActive.push(1); var tmpArr1:Array = new Array(); var tmpArr2:Array = new Array(); for (j = 0; j < numGlossTerms; j ++) { tmpArr1.push (gl_xml.firstChild.childNodes [i].childNodes [j].childNodes [0].childNodes [0].nodeValue); tmpArr2.push (gl_xml.firstChild.childNodes [i].childNodes [j].childNodes [1].childNodes [0].nodeValue); } glTerms_array.push (tmpArr1); glDefs_array.push (tmpArr2); } } // ref_xml.load ("xml/references.xml"); ref_xml.onLoad = Delegate.create (this, refsLoad); } else { _root.debug_txt.text = "Keypoints XML failed to load"; } } public function refsLoad (bSuccess : Boolean) { if (bSuccess){ //Sort keypoints numRefs = ref_xml.firstChild.childNodes.length; for (i = 0; i < numRefs; i ++){ refID_array.push (ref_xml.firstChild.childNodes[i].attributes.id); refRef_array.push (ref_xml.firstChild.childNodes[i].childNodes[0].nodeValue); } // } else { _root.debug_txt.text = "Keypoints XML failed to load"; } _root.id_txt.text = refRef_array; } } ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com
RE: [Flashcoders] variable scope
Is it because the variable gets setup outside the constructer function? From: [EMAIL PROTECTED] on behalf of Helmut Granda Sent: Sun 09/09/2007 15:24 To: flashcoders@chattyfig.figleaf.com Subject: Re: [Flashcoders] variable scope if you are just extending from ClassA you should be able to do something like this: --CLASS A: class ClassA { public var myVar:Number = 50; public function ClassA() {}; } --CLASS B class ClassB extends ClassA{ public function ClassB() { trace(myVar);//this will return 50 } } On 9/9/07, Lee Marshall <[EMAIL PROTECTED]> wrote: > > I have just created a class 'ClassA' that loads an XML file.Within that > class I have a public function that navigates through the XML and populates > arrays with the XML content. > > I am now creating another class, which will be called 'ClassB' which I > plan to extend 'ClassA'. > > >From 'ClassB' I would like to reference the array variable to re-use > in the 'ClassB' class. I have tried tons of different ways all of which I > get undefined. > > Could anyone help? > > Cheers > ___ > Flashcoders@chattyfig.figleaf.com > To change your subscription options or search the archive: > http://chattyfig.figleaf.com/mailman/listinfo/flashcoders > > Brought to you by Fig Leaf Software > Premier Authorized Adobe Consulting and Training > http://www.figleaf.com <http://www.figleaf.com/> > http://training.figleaf.com <http://training.figleaf.com/> > -- ...helmut ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com <http://www.figleaf.com/> http://training.figleaf.com <http://training.figleaf.com/> ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com
RE: [Flashcoders] variable scope
I did, yes Here is a snippet: kp_xml.load ("xml/keypoints.xml"); kp_xml.onLoad = Delegate.create (this, kpLoad); } public function kpLoad (bSuccess : Boolean) { kp_array = new Array; if (bSuccess){ //trace("Keypoints loaded!"); //Sort keypoints numKPs = kp_xml.firstChild.childNodes.length; for (i = 0; i < numKPs; i ++){ kpID_array.push (kp_xml.firstChild.childNodes[i].attributes.id); kp_array.push (kp_xml.firstChild.childNodes[i].childNodes[0].nodeValue); } // //trace(kp_array); gl_xml.load ("xml/glossary.xml"); gl_xml.onLoad = Delegate.create (this, glossLoad); } else { _root.debug_txt.text = "Keypoints XML failed to load"; } } From: [EMAIL PROTECTED] on behalf of o renken Sent: Sun 09/09/2007 14:58 To: flashcoders@chattyfig.figleaf.com Subject: Re: [Flashcoders] variable scope did you tried the Delegate- Class? in sense something like that: import mx.Delegate(i think that path is wrong) //.. ..// Delegate.create(scope,object) cheers olee 2007/9/9, Lee Marshall <[EMAIL PROTECTED]>: > > I have just created a class 'ClassA' that loads an XML file.Within that > class I have a public function that navigates through the XML and populates > arrays with the XML content. > > I am now creating another class, which will be called 'ClassB' which I > plan to extend 'ClassA'. > > >From 'ClassB' I would like to reference the array variable to re-use > in the 'ClassB' class. I have tried tons of different ways all of which I > get undefined. > > Could anyone help? > > Cheers > ___ > Flashcoders@chattyfig.figleaf.com > To change your subscription options or search the archive: > http://chattyfig.figleaf.com/mailman/listinfo/flashcoders > > Brought to you by Fig Leaf Software > Premier Authorized Adobe Consulting and Training > http://www.figleaf.com <http://www.figleaf.com/> > http://training.figleaf.com <http://training.figleaf.com/> > -- http://www.renkster.de/#/about/ ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com <http://www.figleaf.com/> http://training.figleaf.com <http://training.figleaf.com/> ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com
Re: [Flashcoders] variable scope
if you are just extending from ClassA you should be able to do something like this: --CLASS A: class ClassA { public var myVar:Number = 50; public function ClassA() {}; } --CLASS B class ClassB extends ClassA{ public function ClassB() { trace(myVar);//this will return 50 } } On 9/9/07, Lee Marshall <[EMAIL PROTECTED]> wrote: > > I have just created a class 'ClassA' that loads an XML file.Within that > class I have a public function that navigates through the XML and populates > arrays with the XML content. > > I am now creating another class, which will be called 'ClassB' which I > plan to extend 'ClassA'. > > >From 'ClassB' I would like to reference the array variable to re-use > in the 'ClassB' class. I have tried tons of different ways all of which I > get undefined. > > Could anyone help? > > Cheers > ___ > Flashcoders@chattyfig.figleaf.com > To change your subscription options or search the archive: > http://chattyfig.figleaf.com/mailman/listinfo/flashcoders > > Brought to you by Fig Leaf Software > Premier Authorized Adobe Consulting and Training > http://www.figleaf.com > http://training.figleaf.com > -- ...helmut ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com
Re: [Flashcoders] variable scope
Hello :) can you show your code ? else try it : import mx.utils.Delegate ; class Test { function Test() { x = new XML() ; x.onLoad = Delegate.create(this, onLoad) ; // create a proxy between your instance and the xml object x.load("test.xml") ; } public var x:XML ; public function onLoad( success:Boolean ):Void { trace( "scope of your function : " + this) ; trace("xml : " + x ) ; // here use your Test methods ! } } The Delegate class of Adobe can be your solution ? In my opensource framework i use more powerful Delegate implementation and event model, you can read : - http://code.google.com/p/vegas/wiki/VegasTutorialsEvents_delegate - http://code.google.com/p/vegas/wiki/VegasTutorialsEvents - http://code.google.com/p/vegas/ My vegas.events.Delegate class is more complete ... but the Adobe class it's more easy to begin with the proxy model. EKA+ :) 2007/9/9, Lee Marshall <[EMAIL PROTECTED]>: > > I have just created a class 'ClassA' that loads an XML file.Within that > class I have a public function that navigates through the XML and populates > arrays with the XML content. > > I am now creating another class, which will be called 'ClassB' which I > plan to extend 'ClassA'. > > >From 'ClassB' I would like to reference the array variable to re-use > in the 'ClassB' class. I have tried tons of different ways all of which I > get undefined. > > Could anyone help? > > Cheers > ___ > Flashcoders@chattyfig.figleaf.com > To change your subscription options or search the archive: > http://chattyfig.figleaf.com/mailman/listinfo/flashcoders > > Brought to you by Fig Leaf Software > Premier Authorized Adobe Consulting and Training > http://www.figleaf.com > http://training.figleaf.com > ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com
Re: [Flashcoders] variable scope
did you tried the Delegate- Class? in sense something like that: import mx.Delegate(i think that path is wrong) //.. ..// Delegate.create(scope,object) cheers olee 2007/9/9, Lee Marshall <[EMAIL PROTECTED]>: > > I have just created a class 'ClassA' that loads an XML file.Within that > class I have a public function that navigates through the XML and populates > arrays with the XML content. > > I am now creating another class, which will be called 'ClassB' which I > plan to extend 'ClassA'. > > >From 'ClassB' I would like to reference the array variable to re-use > in the 'ClassB' class. I have tried tons of different ways all of which I > get undefined. > > Could anyone help? > > Cheers > ___ > Flashcoders@chattyfig.figleaf.com > To change your subscription options or search the archive: > http://chattyfig.figleaf.com/mailman/listinfo/flashcoders > > Brought to you by Fig Leaf Software > Premier Authorized Adobe Consulting and Training > http://www.figleaf.com > http://training.figleaf.com > -- http://www.renkster.de/#/about/ ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com