控制闪光灯CS5中的按钮上的声音
问题描述:
我是新来的闪光灯,请原谅这个问题,如果它的超级初学者。控制闪光灯CS5中的按钮上的声音
在我的Flash文档中,我在页面上创建了几个按钮,当用户按下给定按钮时会触发声音。附带的音频长度为1 - 2分钟,所以我想给用户选择关闭给定作品的声音,如果他们愿意的话。
import flash.media.SoundMixer;
myButton.addEventListener(MouseEvent.CLICK,fn_clickHandler);
function fn_clickHandler(IN_Event:MouseEvent):void
{
SoundMixer.stopAll();
}
我想确保用户不会在同一时间播放多个声音,可能有人告诉我如何:我已经遇到了下列AS3页面上的按钮,这样做应用那个?
谢谢
答
我不太确定我完全理解你的问题。但是,如果我这样做是正确的那么这里就是答案:
import flash.events.MouseEvent;
import flash.media.Sound;
import flash.media.SoundChannel;
var SChannel : SoundChannel;
var sound : Sound;
// your sound managing buttons
sound_1.addEventListener (MouseEvent.CLICK, handleChangeSound);
sound_2.addEventListener (MouseEvent.CLICK, handleChangeSound);
sound_3.addEventListener (MouseEvent.CLICK, handleChangeSound);
// sound off button
turn_off.addEventListener (MouseEvent.CLICK, turnOffSound);
// sound off managining function
function turnOffSound (e : MouseEvent) : void
{
SChannel.stop();
SChannel = null;
sound = null;
}
// are sounds in your library Sound_1(), Sound_2(), Sound_3()
function handleChangeSound (e : MouseEvent) : void
{
// in my situation since the button names were sound_1, .._2, .._3
// i can extract the sound id from names of the button.
// if you have some different approach you just need to adopt it.
var soundID : uint = e.target.name.split ('_')[1];
// ifi sound is playing, stop it
if (SChannel)
{
turnOffSound(null);
}
// create new sound, from ID given
switch (soundID)
{
case 1 :
sound = new Sound_1();
break;
case 2 :
sound = new Sound_2();
break;
case 3 :
sound = new Sound_3();
break;
}
// if sound was in the list start playing it.
if (sound)
{
SChannel = sound.play();
}
}
顺便说一下,使用SoundMixer
,只有当你指的全闪存页面去无声。