gpt4 book ai didi

flash - 如何在 Flash 中的 AS3 脚本中向现有歌曲添加 2 首歌曲?

转载 作者:行者123 更新时间:2023-12-03 02:21:12 25 4
gpt4 key购买 nike

由于我是 Flash CS6 actionscript 3 的新手,有人可以具体地举一个详细的例子,向我解释一下如何向我的播放器添加 2 首歌曲,并且仍然使用当前的播放和暂停按钮来控制它们吗?

非常感谢!

import flash.media.Sound;
import flash.media.SoundChannel;
import flash.events.MouseEvent;

var mySound:Sound = new heyjude();
var myChannel:SoundChannel = new SoundChannel();
var lastPosition:Number = 0;

pause_btn.addEventListener(MouseEvent.CLICK, onClickPause);

function onClickPause(e:MouseEvent):void{
lastPosition = myChannel.position;
myChannel.stop();
}

play_btn.addEventListener(MouseEvent.CLICK, onClickPlay);

function onClickPlay(e:MouseEvent):void{
myChannel.stop()
myChannel = mySound.play(lastPosition);
}

最佳答案

我只是假设有四个标题/标题按钮和四个标题 channel 来编写这个示例代码。我有一个标题声音的声道。我可以停止或暂停或播放声音。简单地说,我可以使用 titleChannel 控制标题声音.

import flash.media.Sound;
import flash.media.SoundChannel;
import flash.events.MouseEvent;

var titleSound1:Sound = new TitleSound1();
var titleSound2:Sound = new TitleSound2();
var titleSound3:Sound = new TitleSound3();
var titleSound4:Sound = new TitleSound4();

var mySound:Sound = new heyjude();

var titleChannel:SoundChannel;
var myChannel:SoundChannel;

var lastPosition:Number = 0;

titleBtn1.addEventListener(MouseEvent.CLICK, title1Selected);
titleBtn1.addEventListener(MouseEvent.CLICK, title2Selected);
titleBtn1.addEventListener(MouseEvent.CLICK, title3Selected);
titleBtn1.addEventListener(MouseEvent.CLICK, title4Selected);

play_btn.addEventListener(MouseEvent.CLICK, onClickPlay);
pause_btn.addEventListener(MouseEvent.CLICK, onClickPause);

function title1Selected(e:MouseEvent){
if(titleChannel != null) titleChannel.stop();
titleChannel = titleSound1.play();
}

function title2Selected(e:MouseEvent){
if(titleChannel != null) titleChannel.stop();
titleChannel = titleSound2.play();
}

function title3Selected(e:MouseEvent){
if(titleChannel != null) titleChannel.stop();
titleChannel = titleSound3.play();
}

function title4Selected(e:MouseEvent){
if(titleChannel != null) titleChannel.stop();
titleChannel = titleSound4.play();
}

function onClickPause(e:MouseEvent):void{
lastPosition = myChannel.position;
myChannel.stop();
}

function onClickPlay(e:MouseEvent):void{
myChannel.stop()
myChannel = mySound.play(lastPosition);
}

如果您想像其他声音一样暂停和恢复标题声音的播放,请执行与 myChannel 相同的操作。在函数 onClickPauseonClickPlay .

注意:如果您想为某个事件播放声音(如背景或爆炸期间或其他),并且该事件经常发生,请不要犹豫 SoundChannel例如那个声音来控制那个声音。

关于flash - 如何在 Flash 中的 AS3 脚本中向现有歌曲添加 2 首歌曲?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12506185/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com