电影沉默,直到按下按钮,闪光灯AS3
问题描述:
我想我可以改变布尔值true/false值,但它不工作。我如何获得这个嘘,直到按下按钮?电影沉默,直到按下按钮,闪光灯AS3
import flash.media.Sound;
import flash.media.SoundChannel;
var soundOn:Boolean = true; //music is ON when we start
var myToons:TitleMusic = new TitleMusic();
var myChannel:SoundChannel = myToons.play(0,1000); // endless loop, in effect
var myTransform:SoundTransform;
mySoundButton.addEventListener(MouseEvent.CLICK,toggleSound);
mySoundButton.buttonMode = true;
mySoundButton.mouseChildren = false;
function toggleSound(e:MouseEvent)
{
if(soundOn)
{
// turn sound off
myTransform = new SoundTransform();
myTransform.volume = 0; // silent
myChannel.soundTransform = myTransform;
soundOn = false;
mySoundButton.myButtonText.text = "click to turn sound ON";
}
else // sound is off
{
// turn sound on
myTransform = new SoundTransform();
myTransform.volume = 1; // full volume
myChannel.soundTransform = myTransform;
soundOn = true;
mySoundButton.myButtonText.text = "click to turn sound OFF";
}
}
答
不需要布尔语句。这就是我所做的。
变量 '为mySound' 实例化的声音。我把声音的控制权交给'myChannel'。组件面板中的按钮在那里给出名称。确保正确设置您的mp3属性,名称为'Sound,Class'Sound'。一切都应该工作!
播放和停止嵌入的mp3
/*
place mp3 in library.
Give it a Name and Class of 'Sound'
*/
var mySound:Sound = new Sound();
//control the channel that your sound is on
var myChannel:SoundChannel = new SoundChannel();
playButton.addEventListener (MouseEvent.CLICK, myPlayButtonHandler);
/*
Grab a Play and Stop button from the components menu.
Go to Properties Panel and give each an instance name.
Play is 'playButton', Stop is 'stopButton'
*/
function myPlayButtonHandler (e:MouseEvent):void {
//mySound.play();//use channel instead
myChannel = mySound.play();
}
//Stopping the sound channel
stopButton.addEventListener(MouseEvent.CLICK, onClickStop);
function onClickStop(e:MouseEvent):void{
myChannel.stop();
}
加载外部MP3选项
//URL load and auto play of external file "myMp3.mp3"
var mySound:Sound = new Sound();
snd.load(new URLRequest("myMp3.mp3"));
snd.play();
谢谢你,救了我的屁股。我找不到像这样的任何教程。再次感谢:) – pixelGreaser 2010-04-03 20:58:54