If you can reduce this down to an actual simple test case, post it here or file a bug. Your "crazy" function is strange in that it does not work in the clauses and thus might in fact be a compiler bug, but if there's actual work being done, then it would be interesting to see what's going on.
________________________________ From: [email protected] [mailto:[EMAIL PROTECTED] On Behalf Of dbronk Sent: Wednesday, September 26, 2007 12:54 PM To: [email protected] Subject: [flexcoders] Re: Very strange runtime behavior - if logic doesn't work????? Okay, sorry guys. I tried to give just snippets and in doing so I believe I pushed you into the wrong direction. My actual code is NOT public function crazy(myBool:Boolean) : void { if ( myBool ) { var s:String; } else { var ss:String; } } That I did just so I could remove a lot of unnecessary logic out of the picture. My actual code is: function filter(includeBase:Boolean) : void { if ( includeBase ) { // Do a whole lot of stuff here. // Including updating bound variables, etc. } // After if do the rest of my merge process. } My problem was that if I passed in true or false, it always went into the true block of the if statement. So that is when I created my test function of crazy. So let's forget about that test function (although, there were not dup names. One var is "s", the other is "ss"). So, my function has several things it will be doing inside of the true portion of the if statement, and then whether or not it was true or false, continue with other processes. After creating my "crazy" test function I then came back and modified my function to: function filter(includeBase:Boolean) : void { if ( includeBase ) { // Do a whole lot of stuff here. // Including updating bound variables, etc. } else { // HACK FOR AN APPARENT BUG! // Not sure why, but this if statement will always resolve to true unless there is an else. var whoKnowsWhy : String; } // After if do the rest of my merge process. } Once I did this, my code works great. includeBase of true and it will go into the true block. includeBase of false and it will go into the false block. This is very strange. Dale --- In [email protected] <mailto:flexcoders%40yahoogroups.com> , "Tracy Spratt" <[EMAIL PROTECTED]> wrote: > > Actually, this is by design, as of AS3. > > > > The compiler has detected a duplicate definition for a variable. This > can lead to unexpected results. ActionScript does not support block > level scoping of variables. All variables defined within a function body > exist within the same scope, even if they are defined within an if > statement, while statement, for statement, and so on: for example, the > following code redeclares the variable x twice: > > > > function test() { > > var x:Number = 10; > > if (true) { > > for (var x=0; x < 5; x++) // warning here, this is the > second defintion of x > > trace(x); > > } > > trace(x); // 5, not 10. The last value set by the for loop > above is the current value of x > > } > > > > Tracy > > > > ________________________________ > > From: [email protected] <mailto:flexcoders%40yahoogroups.com> [mailto:[email protected] <mailto:flexcoders%40yahoogroups.com> ] On > Behalf Of Seth Caldwell > Sent: Wednesday, September 26, 2007 1:35 PM > To: [email protected] <mailto:flexcoders%40yahoogroups.com> > Subject: RE: [flexcoders] Very strange runtime behavior - if logic > doesn't work????? > > > > This might be a compiler optimization issue. Try putting something in > the if statement that actually matters instead of just a variable > declaration that is never used... > > Like a global variable, for example: > > > > <?xml version="1.0" encoding="utf-8"?> > > <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml <http://www.adobe.com/2006/mxml> " > layout="absolute"> > > <mx:Script> > > <![CDATA[ > > [Bindable] > > var g:Number = 0; > > public function testit(myBool:Boolean):void > > { > > if(myBool) > > { > > g++; > > } > > } > > > > ]]> > > </mx:Script> > > <mx:Button x="273" y="345" label="{g}" > click="testit(false)"/> > > </mx:Application> > > > > It stays 0 when I click the button... > > How are you calling your crazy function? > > > > Seth > > ________________________________ > > From: [email protected] <mailto:flexcoders%40yahoogroups.com> [mailto:[email protected] <mailto:flexcoders%40yahoogroups.com> ] On > Behalf Of dbronk > Sent: Wednesday, September 26, 2007 10:10 AM > To: [email protected] <mailto:flexcoders%40yahoogroups.com> > Subject: [flexcoders] Very strange runtime behavior - if logic doesn't > work????? > > > > Very strange... > > I had an apparent bug in my code and simply could not find it so I > created a very basic function to help test. Here is the code: > > public function crazy(myBool:Boolean) : void > { > if ( myBool ) > { > var s:String; > } > } > > Yes, it does nothing. I place a break point on the var s:String; line > to test the logic of the if statement. When I execute, it does not > matter if I send in a true or a false to this method, it ALWAYS > evaluates the expression to true, even though I can see in the > debugger myBool is false. I tried: > if ( myBool == true ) > To see if that had any luck. It did not. After scratching my head a > bit I tried: > > public function crazy(myBool:Boolean) : void > { > if ( myBool ) > { > var s:String; > } > else > { > var ss:String; > } > } > > Viola!!! Adding the else and the logic now works fine. Is it a > requirement that I must have an else? If so, why? > > Thanks, > Dale >

