我是3中的菜鸟。
我想要一个AS3中的音乐播放器(带有开始、暂停按钮)代码,我已经在库中导入了音乐,并添加了以下代码
var qMySound:Sound = new mySound1();
qMySound.play(0, 9999);
mySound1是AS链接,它可以工作。
我用代码片段的代码做了一个停止按钮
button_7.addEventListener(MouseEvent.CLICK, fl_ClickToStopAllSounds_6);
function fl_ClickToStopAllSounds_6(event:MouseEvent):void
{
SoundMixer.stopAll();
}
它也能工作,但是现在我想再次启动它,我尝试使用以下代码:
button_1.addEventListener(MouseEvent.CLICK, fl_ClickToGoToAndStopAtFrame_28);
function fl_ClickToGoToAndStopAtFrame_28(event:MouseEvent):void
{
gotoAndStop(1);
}
音乐AS3代码在帧1字节内。
这不管用..。有什么想法吗?
编辑:这是我的代码:
var mySound:Sound = new Sound();
var myChannel:SoundChannel = new SoundChannel();
var myTransform:SoundTransform = new SoundTransform();
var lastPosition:Number = 0;
var mySound:Sound = new mySound1(0,999);
myChannel = mySound.play();
// here is to learn how to deal with volume as well (between 0 and 1)
myTransform.volume = .5;
// setting the SoundTransform instance to the myChannel object
myChannel.soundTransform = myTransform;
pause_btn.addEventListener(MouseEvent.CLICK, onClickPauseHandler, false, 0, true);
play_btn.addEventListener(MouseEvent.CLICK, onClickPlayHandler, false, 0, true);
function onClickPauseHandler(event:MouseEvent):void
{
// getting the current position of the sound
lastPosition = myChannel.position;
// stopping the current sound
myChannel.stop();
}
function onClickPlayHandler(event:MouseEvent):void
{
// playing from the saved position
myChannel = mySound.play(0,999);
}
这个错误就会冒出来。
第8行:在名称空间内部,与mySound的定义存在冲突。
发布于 2015-03-04 07:25:17
您需要使用类SoundChannel/SoundTransform来具有更多的功能。当您使用SoundMixer.stopAll()停止所有声音时,并不是要停止相应的声音。
遵循一些示例代码,您可以指导您实现您所期望的目标,另外,还要提供一些关于如何处理声音的额外知识。
var mySound:Sound = new Sound();
var myChannel:SoundChannel = new SoundChannel();
var myTransform:SoundTransform = new SoundTransform();
var lastPosition:Number = 0;
mySound.load(new URLRequest('yourMp3FileName.mp3'));
myChannel = mySound.play();
// here is to learn how to deal with volume as well (between 0 and 1)
myTransform.volume = .5;
// setting the SoundTransform instance to the myChannel object
myChannel.soundTransform = myTransform;
pause_btn.addEventListener(MouseEvent.CLICK, onClickPauseHandler, false, 0, true);
play_btn.addEventListener(MouseEvent.CLICK, onClickPlayHandler, false, 0, true);
function onClickPauseHandler(event:MouseEvent):void
{
// getting the current position of the sound
lastPosition = myChannel.position;
// stopping the current sound
myChannel.stop();
}
function onClickPlayHandler(event:MouseEvent):void
{
// playing from the saved position
myChannel = mySound.play(lastPosition);
}
https://stackoverflow.com/questions/28847417
复制相似问题