AS3勉強 表示オブジェクト

表示オブジェクト

//メインタイムライン:フレームアクション
_mc.x = 150;
_mc.alpha =0.1; //alphaは0~1
_mc.scaleX = 2;

基本は変わらない、_アンダーバーがなくなったくらいか?
あとは、scaleX,scaleYとalphaが0~1になったのが注意点!

ランダムで動かす。

set_btn.addEventListener(MouseEvent.CLICK,xClick);
function xClick(evt){
_mc.scaleX = Math.random() * 1.5 + 0.5;
_mc.scaleY = Math.random() * 1.5 + 0.5;
}

これで0.5~2倍に変動する。

Math.random()は0~1をランダムで返すから、alphaはそのままでOKだけど、座標などの場合は掛けないといけない。

0~550の範囲のランダム値は
Math.random()  * 550
となり

-10~10までの範囲のランダム値は
Math.floor(Math.random() * 21) -10
となる

ランダム値が0なら-10
1なら約21(20.9999999)で小数点切捨てで20-10となる

Math.floor(Math.random() * 301) +50; //50~350
Math.floor(Math.random() * 201) +50; //50~250

———————————————————————————————-

表示オブジェクトのコントロール

//イベント処理
right_btn.addEventListener(MouseEvent.CLICK,xClickright);
left_btn.addEventListener(MouseEvent.CLICK,xClickleft);

//Clickイベント
function xClickright(evt){
_mc.removeEventListener(Event.ENTER_FRAME,xEnterleft); //左への動きを削除
_mc.addEventListener(Event.ENTER_FRAME,xEnterright);
}
function xClickleft(evt){
_mc.removeEventListener(Event.ENTER_FRAME,xEnterright); //右への動きを削除
_mc.addEventListener(Event.ENTER_FRAME,xEnterleft);
}

//イベントハンドラ定義
function xEnterright(evt){
_mc.x += 5;
}
function xEnterleft(evt){
_mc.x -= 5;
}

—————————————————————————————-

テキストエリア

input1_txt.border = true; //枠
input2_txt.border = true;

enter_btn.addEventListener(MouseEvent.CLICK,xClick);
function xClick(evt){
output_txt.text = input1_txt.text + ” ” + input2_txt.text;
output_txt.textColor = 0x000099;
output_txt.border = true;
output_txt.background = true; //背景表示
output_txt.backgroundColor = 0xFFFF99; //背景色
}