0

私は Flash CS6 actionscript 3 の初心者なので、具体的に詳細な例を挙げて、プレーヤーにさらに 2 つの曲を追加し、現在の再生ボタンと一時停止ボタンでそれらを制御する方法を説明してもらえますか?

どうもありがとう!

import flash.media.Sound;
import flash.media.SoundChannel;
import flash.events.MouseEvent;

var mySound:Sound = new heyjude();
var myChannel:SoundChannel = new SoundChannel();
var lastPosition:Number = 0;

pause_btn.addEventListener(MouseEvent.CLICK, onClickPause);

function onClickPause(e:MouseEvent):void{
lastPosition = myChannel.position;  
myChannel.stop();
}

play_btn.addEventListener(MouseEvent.CLICK, onClickPlay);

function onClickPlay(e:MouseEvent):void{
myChannel.stop()
myChannel = mySound.play(lastPosition);
}
4

1 に答える 1

0

このサンプルコードは、4つのタイトル/タイトルボタンと4つのタイトルチャネルがあると仮定して作成しました。タイトルサウンド用のサウンドチャンネルを持っています。それで音を止めたり、一時停止したり、再生したりできます。簡単に言うと、を使用してタイトルサウンドを制御できtitleChannelます。

import flash.media.Sound;
import flash.media.SoundChannel;
import flash.events.MouseEvent;

var titleSound1:Sound = new TitleSound1();
var titleSound2:Sound = new TitleSound2();
var titleSound3:Sound = new TitleSound3();
var titleSound4:Sound = new TitleSound4();

var mySound:Sound = new heyjude();

var titleChannel:SoundChannel;
var myChannel:SoundChannel;

var lastPosition:Number = 0;

titleBtn1.addEventListener(MouseEvent.CLICK, title1Selected);
titleBtn1.addEventListener(MouseEvent.CLICK, title2Selected);
titleBtn1.addEventListener(MouseEvent.CLICK, title3Selected);
titleBtn1.addEventListener(MouseEvent.CLICK, title4Selected);

play_btn.addEventListener(MouseEvent.CLICK, onClickPlay);
pause_btn.addEventListener(MouseEvent.CLICK, onClickPause);

function title1Selected(e:MouseEvent){
    if(titleChannel != null) titleChannel.stop();
    titleChannel = titleSound1.play();
}

function title2Selected(e:MouseEvent){
    if(titleChannel != null) titleChannel.stop();
    titleChannel = titleSound2.play();
}

function title3Selected(e:MouseEvent){
    if(titleChannel != null) titleChannel.stop();
    titleChannel = titleSound3.play();
}

function title4Selected(e:MouseEvent){
    if(titleChannel != null) titleChannel.stop();
    titleChannel = titleSound4.play();
}

function onClickPause(e:MouseEvent):void{
    lastPosition = myChannel.position;  
    myChannel.stop();
}

function onClickPlay(e:MouseEvent):void{
    myChannel.stop()
    myChannel = mySound.play(lastPosition);
}

他のサウンドと同じようにタイトルサウンドの再生を一時停止して再開する場合はmyChannel、関数onClickPauseとで行ったのと同じようにしますonClickPlay

注:イベントのサウンドを再生する場合(バックグラウンドやブラスト中など)、そのイベントが頻繁に発生する場合は、そのサウンドのSoundChannelインスタンスを用意して、そのサウンドを制御することを躊躇しないでください。

于 2012-09-24T04:42:09.863 に答える