The life and times creating engaging media experiences.
« Previous | Main | Next »

Streamline Code Using The Conditional Operator

Instead of writing 5 lines of ActionScript code for a simple if..else block, you can achieve the same logic in 1 line of code using the "?:" conditional operator.

For example, the following piece of code...

     if (x < 5) {
          y = 1;
     } else {
          y = 2;
     }

... can be written in one line as follows...

     y = (x < 5) ? 1 : 2;

More information about the conditionanl operator can be found in the official Adobe documentation.

« Previous | Main | Next »