Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/actionscript-3/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Actionscript 3 增加和减少自动存储塔的容量(Actionscript 3)_Actionscript 3_Flash_Actionscript_Flash Cs5_Volume - Fatal编程技术网

Actionscript 3 增加和减少自动存储塔的容量(Actionscript 3)

Actionscript 3 增加和减少自动存储塔的容量(Actionscript 3),actionscript-3,flash,actionscript,flash-cs5,volume,Actionscript 3,Flash,Actionscript,Flash Cs5,Volume,所以我一直在为这个自动存储塔任务工作一段时间了。我偶然发现了一个与播放动画时更改自动存储塔音量有关的问题。 以下是我试图使用的代码: var st:SoundTransform = new SoundTransform(); st.volume = 0.3; SoundMixer.soundTransform = st; 虽然这段代码本身工作得很好,但当我尝试将其添加到脚本中时,它对音量没有影响。(上面的代码没有添加到下面的代码中,因为它不起作用) 这是我的剧本: import flash.m

所以我一直在为这个自动存储塔任务工作一段时间了。我偶然发现了一个与播放动画时更改自动存储塔音量有关的问题。 以下是我试图使用的代码:

var st:SoundTransform = new SoundTransform();
st.volume = 0.3;
SoundMixer.soundTransform = st;
虽然这段代码本身工作得很好,但当我尝试将其添加到脚本中时,它对音量没有影响。(上面的代码没有添加到下面的代码中,因为它不起作用)

这是我的剧本:

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之间的任何其他数字。

您也可以极大地优化代码,并且对于此任务,您不需要SoundMixer,您的声音和
声音通道也很容易访问。主要思想是一次管理一个声音频道
SoundChannel

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];
    }
}