AS3勉強 条件分岐

これは同じ

ifとかelse

よくある、ステージの端から端へ移動するやつ、移動変数stepXに-1かけて
5と-5に変えている

//メインタイムライン:フレームアクション
var stepX:int = 5;
_mc.addEventListener(Event.ENTER_FRAME, xEnterFrame);
function xEnterFrame(evt) {
_mc.x += stepX;
if(_mc.x >= 400){
stepX *= -1;
}
if(_mc.x <= 0){
stepX *= -1;
}
}

——————————————————————————–

2分の1の確立
if (Math.random() < 0.5){
stepY *= -1;
}

—————————————————————————–

ランダムぽい動き

//メインタイムライン:フレームアクション
var stepX:int = Math.floor(Math.random() * 6) + 5;
var stepY:int = Math.floor(Math.random() * 6) + 5;
if (Math.random() < 0.5){
stepX *= -1;
}
if (Math.random() < 0.5){
stepY *= -1;
}
_mc.addEventListener(Event.ENTER_FRAME, xEnterFrame);
function xEnterFrame(evt) {
_mc.x += stepX;
_mc.y += stepY;
if (_mc.x >= 400 || _mc.x <= 0){
stepX *= -1;
}
if (_mc.y >= 300 || _mc.y <= 0){
stepY *= -1;
}
}