//メインタイムライン:フレームアクション
//変数定義
var sndCh:SoundChannel;
//Soundオブジェクトの作成
var snd:Sound = new BGM();
//イベント処理
play_btn.addEventListener(MouseEvent.CLICK, xPlayClick);
stop_btn.addEventListener(MouseEvent.CLICK, xStopClick);
on_btn.addEventListener(MouseEvent.CLICK, xOnClick);
off_btn.addEventListener(MouseEvent.CLICK, xOffClick);
//イベントハンドラ定義
function xPlayClick(evt:MouseEvent):void {
//何度も押されても音が重ならないようにする
if (sndCh == null){
sndCh = snd.play(0, 1000);
}
}
function xStopClick(evt:MouseEvent):void {
if (sndCh != null){
sndCh.stop();
sndCh = null;
}
}
function xOnClick(evt:MouseEvent):void {
if (sndCh != null){
var sndTr:SoundTransform = new SoundTransform();
sndTr.volume = 1; //ボリューム
sndCh.soundTransform = sndTr;
}
}
function xOffClick(evt:MouseEvent):void {
if (sndCh != null){
var sndTr:SoundTransform = new SoundTransform();
sndTr.volume = 0;
sndCh.soundTransform = sndTr;
}
}