首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >增大和减小自动存储塔的音量(Actionscript 3)

增大和减小自动存储塔的音量(Actionscript 3)
EN

Stack Overflow用户
提问于 2014-03-09 22:00:09
回答 1查看 231关注 0票数 0

因此,我已经为这个自动存储塔分配工作了一段时间。我偶然发现了一个问题,就是在播放动画时改变自动点唱机的音量。下面是我尝试使用的代码:

代码语言:javascript
复制
var st:SoundTransform = new SoundTransform();
st.volume = 0.3;
SoundMixer.soundTransform = st;

虽然这段代码本身工作得很好,但当我尝试将它添加到脚本中时,它对音量水平没有任何影响。(上面的代码没有添加到下面的代码中,因为它不起作用)

下面是我的脚本:

代码语言:javascript
复制
import flash.media.Sound;
import flash.net.URLRequest;
import flash.events.Event;
import flash.events.ProgressEvent;
import flash.media.SoundTransform;

//Equalizer
var _sound1         :Sound          = null;
var _sound2         :Sound          = null;
var _sound3         :Sound          = null;
var _sound4         :Sound          = null;
var _sound5         :Sound          = null;
var _sound6         :Sound          = null;
var _sound7         :Sound          = null;
var _sound8         :Sound          = null;

//Volume

var _soundChannel   :SoundChannel   = null;
_soundChannel = new SoundChannel();

//Sanger
_sound1 = new Sound(new URLRequest("lyd1.mp3"));
_sound2 = new Sound(new URLRequest("lyd2.mp3"));
_sound3 = new Sound(new URLRequest("lyd3.mp3"));
_sound4 = new Sound(new URLRequest("lyd4.mp3"));
_sound5 = new Sound(new URLRequest("lyd5.mp3"));
_sound6 = new Sound(new URLRequest("lyd6.mp3"));
_sound7 = new Sound(new URLRequest("lyd7.mp3"));
_sound8 = new Sound(new URLRequest("lyd8.mp3"));


//Spille sanger
knapp1.addEventListener(MouseEvent.CLICK, spill1);
knapp2.addEventListener(MouseEvent.CLICK, spill2);
knapp3.addEventListener(MouseEvent.CLICK, spill3);
knapp4.addEventListener(MouseEvent.CLICK, spill4);
knapp5.addEventListener(MouseEvent.CLICK, spill5);
knapp6.addEventListener(MouseEvent.CLICK, spill6);
knapp7.addEventListener(MouseEvent.CLICK, spill7);
knapp8.addEventListener(MouseEvent.CLICK, spill8);

function spill1(event:MouseEvent)
{
    SoundMixer.stopAll();
    _soundChannel = _sound1.play();
    skjermTekst.text = "Miami Nights - Ocean Drive";
}

function spill2(event:MouseEvent)
{
    SoundMixer.stopAll();
    _soundChannel = _sound2.play();
    skjermTekst.text = "Likelike - So Electric";
}

function spill3(event:MouseEvent)
{
    SoundMixer.stopAll();
    _soundChannel = _sound3.play();
    skjermTekst.text = "LazerHawk - Disco Planet";
}

function spill4(event:MouseEvent)
{
    SoundMixer.stopAll();
    _soundChannel = _sound4.play();
    skjermTekst.text = "Garth Knight - Silent Strike";
}

function spill5(event:MouseEvent)
{
    SoundMixer.stopAll();
    _soundChannel = _sound5.play();
    skjermTekst.text = "Mitch Murder - Terminator Theme";
}

function spill6(event:MouseEvent)
{
    SoundMixer.stopAll();
    _soundChannel = _sound6.play();
    skjermTekst.text = "Dynatron - Stars of the Night";
}

function spill7(event:MouseEvent)
{
    SoundMixer.stopAll();
    _soundChannel = _sound7.play();
    skjermTekst.text = "Electric Youth - The Best Thing";
}

function spill8(event:MouseEvent)
{
    SoundMixer.stopAll();
    _soundChannel = _sound8.play();
    skjermTekst.text = "Borgeoisie - Neon Black";
}

//Equalizer

addEventListener(Event.ENTER_FRAME, Update, false, 0, true)

function Update($e:Event):void
{
    _equalizer._eq1.gotoAndStop (Math.round(_soundChannel.leftPeak  * 3) ); 
    _equalizer._eq2.gotoAndStop (Math.round(_soundChannel.rightPeak * 5) );
    _equalizer._eq3.gotoAndStop (Math.round(_soundChannel.leftPeak * 7) ); 
    _equalizer._eq4.gotoAndStop (Math.round(_soundChannel.rightPeak * 9) );
    _equalizer._eq5.gotoAndStop (Math.round(_soundChannel.leftPeak * 11) ); 
    _equalizer._eq6.gotoAndStop (Math.round(_soundChannel.rightPeak * 13) );
    _equalizer._eq7.gotoAndStop (Math.round(_soundChannel.leftPeak * 15) );
    _equalizer._eq8.gotoAndStop (Math.round(_soundChannel.rightPeak * 17) );
    _equalizer._eq9.gotoAndStop (Math.round(_soundChannel.leftPeak  * 17) ); 
    _equalizer._eq10.gotoAndStop (Math.round(_soundChannel.rightPeak * 15) );
    _equalizer._eq11.gotoAndStop (Math.round(_soundChannel.leftPeak * 13) ); 
    _equalizer._eq12.gotoAndStop (Math.round(_soundChannel.rightPeak * 11) );
    _equalizer._eq13.gotoAndStop (Math.round(_soundChannel.leftPeak * 9) ); 
    _equalizer._eq14.gotoAndStop (Math.round(_soundChannel.rightPeak * 7) );
    _equalizer._eq15.gotoAndStop (Math.round(_soundChannel.leftPeak * 5) );
    _equalizer._eq16.gotoAndStop (Math.round(_soundChannel.rightPeak * 3) ); 
}

现在,添加了卷片段后,光盘机的音量保持不变。即使我将st.volume = 0.3更改为0到1之间的任何其他数字。

EN

回答 1

Stack Overflow用户

发布于 2014-03-10 17:15:15

你可以极大地优化你的代码,而且你不需要SoundMixer,你的声音和SoundChannels很容易访问。主要思想是在time SoundChannel中管理一个

代码语言:javascript
复制
const soundKey:String = "sound";
const soundNameKey:String = "soundName";
var sounds:Dictionary = new Dictionary();
var mainChannel:SoundChannel;
var volume:SoundTransform = new SoundTransform(1);

//"Bind" your buttons to the corresponding Sound description
sounds[knapp1] = {"sound": new Sound(new URLRequest("path")), "soundName": "Miami Nights - Ocean Drive"};
//Add all your sounds
//sounds[knapp8] = ...;

//Add all knapp buttons to the one container
//myKnappContainer.addChild(knapp1); ...

myKnappContainer.addEventListener(MouseEvent.CLICK, onClick);

function onClick(e:MouseEvent):void {
    var soundInfo:Object = sounds[e.target];
    if (soundInfo != null) {
        if (mainChannel != null) {
            //Stop previous sound
            mainChannel.stop();
        }

        //Start a new
        mainChannel = Sound(soundInfo[soundKey]).play();
        //Apply current volume
        mainChannel.soundTransform = volume;

        //Display sound name
        skjermTekst.text = soundInfo[soundNameKey];
    }
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/22283104

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档