我试着让时间线上的声音在我按下按钮的时候停下来并播放。在这个时间线上也有一个动画,应该停下来播放。我不能得到我用来工作的代码。我收到错误
Del1,层“actions”,第1帧,第16行1061行:通过静态类型flash.media:SoundChannel的引用调用可能未定义的方法play。
Del1,层'actions',第1帧,第10行1120:访问未定义的属性fireworks。
我是新手,我不知道如何修复错误和让按钮工作。
下面是完整的代码
import flash.events.MouseEvent;
import flash.media.Sound;
import flash.media.SoundChannel;
PlayButton.addEventListener(MouseEvent.CLICK, playbutton);
NextButton.addEventListener(MouseEvent.CLICK, nextbutton);
StopButton.addEventListener(MouseEvent.CLICK, stopbutton);
var mySound:Sound = new fireworks.wav();
var myChannel:SoundChannel = new SoundChannel();
myChannel = mySound.play();
function playbutton(event:MouseEvent):void
{
myChannel.play();
play();
}
function stopbutton(event:MouseEvent):void
{
stop();
myChannel.stop();
}
function nextbutton(event:MouseEvent):void
{
gotoAndPlay(1, "Del2");
}发布于 2013-10-05 23:20:52
您的第一个错误:无法在play() SoundChannel上调用
虽然您总是可以stop()您的myChannel对象,但您不能简单地播放它。有关您尝试构建的功能的信息,请参阅标题为在this tutorial中暂停声音的小节。基本上,当您暂停您的歌曲时,您需要记住歌曲中的位置,然后在您想要恢复时调用myChannel = mySound.play(thatLocation);。
你的第二个错误:添加你的歌曲文件的语法需要改变一点
如果歌曲文件在Flash之外的某个地方,比如文件夹中-
var mySound:Sound = new Sound();
mySound.load(new URLRequest("fireworks.wav"));
mySound.play();如果歌曲文件已加载到Flash库中-
var mySound:Sound = new CustomSongNameHere();
mySound.play();但在这种情况下,您需要在Flash库中找到歌曲,右键单击它,选择Linkage,选中Export for ActionScript,然后将Class字段更改为CustomSongNameHere或您在代码中使用的任何内容。
https://stackoverflow.com/questions/19197044
复制相似问题