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"; 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:[EMAIL PROTECTED] On
Behalf Of dbronk
Sent: Wednesday, September 26, 2007 10:10 AM
To: [email protected]
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

 

Reply via email to