如何更改阵列的音量?

时间:2013-11-11 02:58:27

标签: actionscript-3 flash

我正试图在游戏中制作一些声音数组。单击文本字段时,音量会根据数字的值减小或增大。我试过这样做,但是发生了错误。我的代码出了什么问题?

import flash.events.MouseEvent;
import flash.media.SoundChannel;
var onoff:Number;
onoff = 2
var mysoundArray:Array = new Array(tchannel,Mchannel);
var volControl:SoundTransform = mysoundArray.soundTransform;
options_mc.onoff_txt.text = String(onoff);
options_mc.onoff_txt.addEventListener(MouseEvent.CLICK, tick);
function tick(event:MouseEvent)
{
if(onoff == 1)
{
onoff = 2
options_mc.onoff_txt.text = String(onoff);
volControl.volume = .5;
mysoundArray.soundTransform = volControl;
}
else if(onoff == 2)
{
onoff = 1
options_mc.onoff_txt.text = String(onoff);
volControl.volume = 1;
mysoundArray.soundTransform = volControl;

}
}

1 个答案:

答案 0 :(得分:0)

您的代码有多处错误。

错误1:tchannelMchannel来自哪里?

var mysoundArray:Array = new Array(tchannel,Mchannel);

错误2:数组mysoundArray没有名为soundTransform的子对象。

var volControl:SoundTransform = mysoundArray.soundTransform;

因此,对象volControl为空。修复上述错误,您的问题将得到解决。