Actionscript 3 Actionscript 3访问不同电影时同时播放多个声音
我目前正在尝试创建一部交互式电影,其结构使时间轴中的每个关键帧都包含一个使用movieclips中的按钮导航到的movieclip,并在主时间轴中包含相应的代码 现在的问题是,当您访问第3帧内的movieclip时,第2帧的声音也会同时播放。在做了一些研究之后,我发现这似乎是flash本身的一个bug,大多数情况下都是使用SoundMixer.stopAll()处理的;。遗憾的是,我不知道如何在只访问第3帧时使用它来消除第2帧的声音 我知道,当访问第2帧时,只播放第2帧,这意味着flash基本上会在到达您应该到达的帧的过程中通过所有帧 这是我目前使用的有限代码: 第1帧:Actionscript 3 Actionscript 3访问不同电影时同时播放多个声音,actionscript-3,flash,button,movieclip,Actionscript 3,Flash,Button,Movieclip,我目前正在尝试创建一部交互式电影,其结构使时间轴中的每个关键帧都包含一个使用movieclips中的按钮导航到的movieclip,并在主时间轴中包含相应的代码 现在的问题是,当您访问第3帧内的movieclip时,第2帧的声音也会同时播放。在做了一些研究之后,我发现这似乎是flash本身的一个bug,大多数情况下都是使用SoundMixer.stopAll()处理的;。遗憾的是,我不知道如何在只访问第3帧时使用它来消除第2帧的声音 我知道,当访问第2帧时,只播放第2帧,这意味着flash基本上
import flash.events.MouseEvent;
import flash.display.SimpleButton;
import flash.media.SoundMixer;
stop();
var soundVar:int = 0;
var Choice1F:SimpleButton;
var Choice1R:SimpleButton;
this.Val1.Choice1F.addEventListener(MouseEvent.CLICK, function(me:MouseEvent):void{buttonHandler(me, 2)});
this.Val1.Choice1R.addEventListener(MouseEvent.CLICK, function(me:MouseEvent):void{buttonHandler(me, 3)});
function buttonHandler(e:MouseEvent, Value:int): void{
SoundMixer.stopAll();
soundVar = Value;
this.gotoAndPlay(Value);
}
框架2:
import flash.media.SoundMixer;
stop();
if(soundVar == 3){
SoundMixer.stopAll();
}
第3帧只包含一个stop();陈述第2帧中的代码是一个徒劳的尝试,我想让它在进入第3帧的过程中消除声音。希望你们能想出一个更好的解决方案,如果有的话。项目的正确结构假设您使用定制类的一个特殊实例来控制音乐和声音的播放。你们使用的时间线只给了他什么时候做什么的命令。 一个
SoundChannel
和两个Sound
就可以了
你可以用这个
package src.utils{
import flash.media.Sound;
import flash.media.SoundChannel;
import flash.net.URLRequest;
public dynamic class BackgroundMusicPlayer extends Object{
public var playlist;
public var sndChannel;
private var ID;
public function BackgroundMusicPlayer(srcList:Array){
playlist=[];
for(var i=0;i<srcList.length;i++){
var src= new URLRequest(srcList[i]);
var newSound = new Sound(src);
playlist.push(newSound);
}
}
public function playMusic(id){
if (sndChannel!=undefined) {
sndChannel.stop();
}
sndChannel = playlist[id].play();
ID=id;
sndChannel.addEventListener("soundComplete",replayListener);
}
public function replayListener(e){
sndChannel = playlist[ID].play();
}
}
}
然后你想开始一些声音,打电话
musicPlayer.playMusic(0);
如果您想使用导入到项目中的声音,只需将它们共享到actionscript,为它们指定类名,并稍微修改给定的类构造函数
public function BackgroundMusicPlayer(srcList:Array){
playlist=[];
for(var i=0;i<srcList.length;i++){
playlist.push(srcList[i]);
}
}
目前使用的movieclips具有视频和音频内容,这意味着音频是内部的,据我所知,无法通过正常方式访问。当两帧重叠时,有没有办法在不接触第1帧声音的情况下删除第2帧的声音?否则我只需要从原始项目中导出音频。你说不能访问是什么意思?若声音是在fla项目中导入的,那个么它将位于库中,并使用属性检查器添加到框架中。只需将其从框架中移除,在库中添加标识符,然后离开
musicPlayer.playMusic(0)代码>取而代之。从帧中删除声音然后将其添加到IDE中并不是那么简单,因为这是垃圾收集器的工作,您应该可以找到对它的所有引用。movieclips是在FLV文件中导入的,而不是在FLA中导入的。这是一种问题,这就是为什么我建议将原始项目中的音频导出以使用。FLV是Flash视频文件(),看在上帝的份上,如何将MovieClip(ActionScript类)导入其中?)将FLV嵌入SWF,这是将文件导入flash时的一个可行选项。PS:stop()是一个函数
public function BackgroundMusicPlayer(srcList:Array){
playlist=[];
for(var i=0;i<srcList.length;i++){
playlist.push(srcList[i]);
}
}
var musicPlayer = new BackgroundMusicPlayer(new MySound1(),new MySound2());