我正试图在游戏中制作一些声音数组。单击文本字段时,音量会根据数字的值减小或增大。我试过这样做,但是发生了错误。我的代码出了什么问题?
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;
}
}
答案 0 :(得分:0)
您的代码有多处错误。
错误1:tchannel
和Mchannel
来自哪里?
var mysoundArray:Array = new Array(tchannel,Mchannel);
错误2:数组mysoundArray
没有名为soundTransform
的子对象。
var volControl:SoundTransform = mysoundArray.soundTransform;
因此,对象volControl
为空。修复上述错误,您的问题将得到解决。