Search code examples
flashactionscript

Adobe flash AS 2.0 true and false


I don't have really a question i just want to learn how can i use in adobe flash whit ActionScript 2.0 in actions "true" and "false" and for what can i use it ? And please if you can give me examples.


Solution

  • First, don't do AS2. It is 10 years as obsolete and there are reasons to that. Do AS3 instead, it is faster, and structured (both language and Flash platform), and AS3 > AS2 in any possible way.

    Then, your question. Boolean values are intended for data that have only two possible values in a certain context. Like AM or PM time, day or night, male or female, sold out or available, visible or hidden, right or wrong etc.

    The use of Boolean variable is like saying "this data can have only 2 states" which cuts off other possibilities and simplifies the understanding of your program.

    Ultimately, the condition and loop operators require Boolean values. In most cases anything you provide to these operators is auto-converted to Boolean so it's better to explicitly obtain the Boolean values out of your data to keep the logic straight.

    Thus, Boolean variables are to store 2-state data and can be used in programming logic to control the flow of code.

    // Conditional 'if..else' block.
    if (ConditionA:Boolean)
    {
        // Do this if ConditionA is true.
    }
    else if (ConditionB:Boolean)
    {
        // Do this if ConditionB is true while ConditionA is false.
    }
    else
    {
        // Do this if both ConditionA and ConditionB are false.
    }
    
    // The 'for' loop.
    for (ExpressionA; ConditionA:Boolean; ExpressionB)
    {
        // Do the loop while ConditionA is true.
        // Will not run if ConditionA is initially false.
    }
    
    // The 'while' loop.
    while (ConditionA:Boolean)
    {
        // Do the loop while ConditionA is true.
        // Will not run if ConditionA is initially false.
    }
    
    // The 'do..while' loop.
    do
    {
        // Do the loop while ConditionA is true.
        // Will run once even if ConditionA is initially false,
        // because the condition is checked at the end of the loop.
    }
    while (ConditionA:Boolean);
    

    https://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/Boolean.html#includeExamplesSummary