QuickTip: Inline If-Then-Else Statement
This entry is part of a series, Quick Tips»
If you have to do a simple If-Then-Else Statement, it can be tedious to do it this way:
var answer:String; if ( isCreative) { answer = "Aww.. I don't know what to do!"; } else { answer = "Ha, I know just what I'm going to do!"; } |
Here is the easy way:
var answer:String = isCreative ? "Aww.. I don't know what to do!" : "Ha, I know just what I'm going to do!"; |
This is only really useful for simple things, so if you’re checking lots of conditions or performing lots of operations inside the curly brackets, it might be not be a good idea to use this!
Entries in this series:
- QuickTip: Execute Code After Animaiton
- QuickTip: Scrolling Only in SWF, not on Page.
- QuickTip: Managing Saved Data (SharedObject)
- QuickTip: Understanding Right Click Menus (ContextMenu)
- QuickTip: Stopping an Event
- QuickTip: Avoid Firefox popup-blocker When Using navigateToUrl
- QuickTip: Inline If-Then-Else Statement
- QucikTip: Trace an Array With Correct Formatting