Flashドキュメンテーション |
|||
| ActionScript 2.0 の学習 > ActionScript によるインタラクティブ機能の作成 > インタラクティブ機能と視覚効果の作成 > サウンドの制御 | |||
ビルトインクラスである Sound クラスを使用して、SWF ファイル内のサウンドを制御します。Sound クラスのメソッドを使用するには、まず Sound オブジェクトを作成する必要があります。次に、attachSound() メソッドを使用して、SWF ファイルの実行中にサウンドをライブラリから SWF ファイルに挿入します。
サウンド制御のアニメーションによるデモンストレーションを確認するには、[再生] ボタンをクリックし、ボリュームとパンを調節します。
Sound クラスの setVolume() メソッドはボリュームの制御用、setPan() メソッドはサウンドの左右のバランスの調整用です。
以下はサウンド制御を作成するための手順です。
a_thousand_ways を割り当てます。play_btn」という名前を付けます。 stop_btn」という名前を付けます。 [アクション] パネルに次のコードを追加します。
var song_sound:Sound = new Sound();
song_sound.attachSound("a_thousand_ways");
play_btn.onRelease = function() {
song_sound.start();
};
stop_btn.onRelease = function() {
song_sound.stop();
};
このコードでは、まず speaker ムービークリップが停止します。次に、新しい Sound オブジェクト (song_sound) を作成し、リンケージ識別子が a_thousand_ways であるサウンドを割り当てています。playButton オブジェクトおよび stopButton オブジェクトに関連付けられた onRelease イベントハンドラが、Sound.start() メソッドおよび Sound.stop() メソッドを使ってサウンドを開始および停止し、さらに、割り当てられたサウンドを再生および停止します。
必ずムービークリップビヘイビアを選択してください。フレーム 1 にボタンがあるムービークリップが作成されます。
this.createTextField("volume_txt", 10, 30, 30, 200, 20);
volume_mc.top = volume_mc._y;
volume_mc.bottom = volume_mc._y;
volume_mc.left = volume_mc._x;
volume_mc.right = volume_mc._x + 100;
volume_mc._x += 100;
volume_mc.handle_btn.onPress = function() {
startDrag(this._parent, false, this._parent.left, this._parent.top, this._parent.right, this._parent.bottom);
};
volume_mc.handle_btn.onRelease = function() {
stopDrag();
var level:Number = Math.ceil(this._parent._x - this._parent.left);
this._parent._parent.song_sound.setVolume(level);
this._parent._parent.volume_txt.text = level;
};
volume_mc.handle_btn.onReleaseOutside = slider_mc.handle_btn.onRelease;
startDrag() パラメータの left、top、right、および bottom は、ムービークリップアクションで設定される変数です。
必ずムービークリップビヘイビアを選択してください。フレーム 1 にボタンがあるムービークリップが作成されます。
balance_mc.top = balance_mc._y;
balance_mc.bottom = balance_mc._y;
balance_mc.left = balance_mc._x;
balance_mc.right = balance_mc._x + 100;
balance_mc._x += 50;
balance_mc.handle_btn.onPress = function() {
startDrag(this._parent, false, this._parent.left, this._parent.top, this._parent.right, this._parent.bottom);
};
balance_mc.handle_btn.onRelease = function() {
stopDrag();
var level:Number = Math.ceil((this._parent._x - this._parent.left - 50) * 2);
this._parent._parent.song_sound.setPan(level);
};
balance_mc.handle_btn.onReleaseOutside = balance_mc.handle_btn.onRelease;
startDrag() パラメータの left、top、right、および bottom は、ムービークリップアクションで設定される変数です。
Sound クラスのメソッドの詳細については、『ActionScript 2.0 リファレンスガイド』の「Sound」を参照してください。
RSS フィード | このページに新しいコメントが追加された場合に、電子メールでの通知を希望する。 | コメントレポート
現在のページ: http://livedocs.adobe.com/flash/8_jp/main/00001552.html
Comments
Fumio Nonaka が Jan 22, 2006 の 4:12 AM に追加: