我对此真的很陌生,所以,如果有一些我不知何故错过的明显解决方案,我真的很抱歉,但是哦……
我正在制作游戏,我正在尝试制作一个字符选择菜单。每个角色都会有同一首歌曲的唯一版本(具有相同的 bps),因此当您“悬停”其中一个选项时,角色的歌曲会播放,而其他歌曲会静音(不会暂停或停止,所以为了不失去所有版本的歌曲之间的同步)......
现在,我试图只为其中一首歌曲进行编程,然后在我弄清楚后重复其他歌曲的方法。
所以......
我做错了什么?
这是代码:
package {
import flash.display.MovieClip;
import flash.events.Event;
import flash.media.SoundTransform;
import flash.media.Sound;
import flash.media.SoundChannel;
import flash.media.SoundMixer;
public class MainThing extends MovieClip {
private var soulcounting: Number = 1;
private var Muting: Boolean = false;
private var snd:Sound = new Sound();
public function MainThing() {
snd.load(new URLRequest("SOUL1.mp3"));
stage.addEventListener(Event.ENTER_FRAME, FrameHandler);
}
private function FrameHandler(event: Event): void {
if (Object(root).currentFrame == 2) {
var channel:SoundChannel = snd.play(0,1);
channel.soundTransform = new SoundTransform(1,0);
/*the soulcounting number is determined by a keyboard function...
I didn't deem it necessary to be included in here,
as I don't think it is part of the problem.*/
if (soulcounting == 1) {
Object(root).SOULS.gotoAndStop(1);
Muting = false;
}
if (soulcounting == 2) {
Object(root).SOULS.gotoAndStop(2);
Muting = true;
}
if (soulcounting == 3) {
Object(root).SOULS.gotoAndStop(3);
Muting = true;
}
if (soulcounting == 4) {
Object(root).SOULS.gotoAndStop(4);
Muting = true;
}
if (soulcounting == 5) {
Object(root).SOULS.gotoAndStop(5);
Muting = true;
}
if (soulcounting == 6) {
Object(root).SOULS.gotoAndStop(6);
Muting = true;
}
if(Muting){
setVolume(channel);
}
if(!Muting){
setVolume(channel, 1);
}
}
private function setVolume (Soundchannel:SoundChannel, volume:Number=0) {
var trans:SoundTransform = Soundchannel.soundTransform;
trans.volume = volume;
Soundchannel.soundTransform = trans;
}
}
}
(如果我尝试预览 swf,一切正常,直到我到达第二帧,其中输出开始重复TypeError:错误 #1009:无法访问空对象引用的属性或方法。在 MainThing/FrameHandler() )
TypeError #1009 似乎是一个非常常见的错误,但我所阅读的内容并没有真正帮助我解决这个问题......对不起,如果这里已经有解决方案,我只是没有进行足够的搜索。 ..
提前谢谢!