[ create a new paste ] login | about

Link: http://codepad.org/wD6x6ub2    [ raw code | fork ]

Plain Text, pasted on Dec 10:
package {
  import flash.display.MovieClip;
  import flash.utils.Timer;
  import flash.events.TimerEvent;
  import flash.events.MouseEvent;
  
  public class Roulette extends MovieClip {
    var toAngle : Number = 0;/* 目的の角度 */
	var curAngle : Number = 0; /* 現在のルーレット角度 */
	var preAngle : Number = 0; /* 先ほどの角度 */
	var timer : Timer;
	  //プロパティ宣言

    function Roulette() {
      startBt.buttonMode = true; /*スタートボタンにマウスがロールオーバーした時 */
      startBt.useHandCursor = true; /*カーソルが指になる */
      
      this["startBt"].addEventListener(MouseEvent.CLICK, onMClick); /*スタートボタンをクリックした時onMClickメソッドを実行 */

      timer = new Timer(33);
      timer.addEventListener(TimerEvent.TIMER, loop);
      timer.start();
      //コンストラクタメソッド
	}

	function onMClick(event:MouseEvent):void {
      toAngle += 720+Math.floor(Math.random()*12)*30; /* 2周分(720度) + 30度,60度…( (0~1の乱数を表すMath.random() * 12) * 30度) */
      //スタートボタンが押された時の処理
    }

    function loop(event:TimerEvent):void {
      preAngle = curAngle;
      curAngle += (toAngle - curAngle)/30; /* 徐々に進める */
      roulette.rotation = curAngle; /* 上で求められた現在の角度をルーレット盤の角度にあてはめる */

      if(toAngle - curAngle < 1) { /* 今の角度から目的の角度までの角度が1度未満で */
        if(toAngle - preAngle >= 1) { /* かつ、先ほどの角度から目的の角度までの角度が1度以上だった時 */
          light.gotoAndPlay(2); /* ライトの点滅 */
          curAngle = toAngle; /* また、ルーレットのストップ */
		}
	  }else{ /* 上の条件からはずれた時は */
        light.gotoAndStop(1); /* ライトの点滅がStop */
      //常時繰り返される処理
      }
    }
  }
}


Create a new paste based on this one


Comments: