Tutorials, extensions, and source files for ActionScript, Flash, and other Adobe products.

 

senocular.com ActionScript Library

ifElse.as

Name: ifElse() - returns first parameter if true, second if false
Author: senocular: www.senocular.com
Date: 1899-12-31T00:59:27.200
Documentation:
Boolean ifElse: returns one of 2 statements based on value of
boolean. A form of ?: which can be inserted directly into strings.
 
Arguments
- a: statement 1 - returned value if boolean is true
- b: statement 2 - returned value if boolean is false

Example:
answer = new Boolean(true);
response = "You said "+ answer.ifElse("yes","no") +" to dating my sister?";
trace(response); // traces You said yes to dating my sister?

1
2
3
Boolean.prototype.ifElse = function(a,b){
	return (this.valueOf()) ? a : b;
}