![]() ![]() | |
Flash Player 4。
if (condition){statement(s); } else if (condition){statement(s); }
condition 计算结果为 true 或 false 的表达式。
statement(s) 当 if 语句中指定的条件为 false 时运行的替代语句系列。
无。
语句;计算条件,并指定当初始 if 语句中的条件返回 false 时要运行的语句。如果 else if 条件返回 true,则 Flash 解释程序运行该条件后面花括号 ({}) 中的语句。如果 else if 条件为 false,则 Flash 将跳过花括号中的语句,而运行花括号之后的语句。使用 else if 动作可在脚本中创建分支逻辑。
下面的示例使用 else if 动作检查对象的每一边是否都在特定的边界内:
// 如果对象超出边界,
// 则将其发回并倒转其行进路径
if (this._x>rightBound) {
this._x = rightBound;
xInc = -xInc;
} else if (this._x<leftBound) {
this._x = leftBound;
xInc = -xInc;
} else if (this._y>bottomBound) {
this._y = bottomBound;
yInc = -yInc;
} else if (this._y<topBound) {
this._y = topBound;
yInc = -yInc;
}
![]() ![]() | |