Search code examples
actionscript-3apache-flexflash-buildermxml

How i write inline conditional statement in Flex with two expressions(case)?


How i write the inline conditional statement in Flex with two expressions(case)

like

text="{expression, expression2 ? true:false}"

Flex compiler only check the first expression and on behalf of that give result.But i want to check both statement and show result. if no condition met then do nothing.


Solution

  • If you want them in one if statement, use the and or or operators: &&~ and||`, respectively. For example:

    var x:int = 6
    if (x > 3 && x < 10) {
        trace("both are true, so its contents will be acted on.");
    }
    
    var bob:Boolean = true;
    if (x > 10 || bob) {
        trace("x > 10 is false, but bob is true, so this will also be acted on.");
    }
    

    You can also use functions that return booleans

    function y (z:int):Boolean {
        if (z < 10) {
            return false;
        } else {
            return true;
        }
    }
    

    Actually, I could simplify that to

    function y (z:int) {
        return z >= 10;
    }
    

    Then use the function in a group of conditions:

    if (x < 5 && y(x)) { trace ("something here"); }
    

    Booleans are converted to strings if assigned to or concatenated with a String.