【发布时间】:2013-08-21 19:57:55
【问题描述】:
代码如下:
function playSound():void
{
var channel:SoundChannel = sound.play();
channel.addEventListener(Event.SOUND_COMPLETE, onComplete);
}
function onComplete(event:Event):void
{
SoundChannel(event.target).removeEventListener(event.type, onComplete);
playSound();
}
我在channel.addEventListener(Event.SOUND_COMPLETE, onComplete); 上收到错误消息
但我一开始没有得到它,因为游戏运行了一段时间没有错误,所以我建议 onComplete 函数或事件侦听器有问题,但是,我尝试的所有方法都失败了,我在这里停留了一段时间现在是时候了。
我只是决定在这里发布它,看看是否有人能看到问题。
提前致谢!
编辑: 抱歉,我没有立即加入。
错误:
TypeError:错误 #1009:无法访问 null 的属性或方法 对象引用。在 projectSnowFlake_fla::MainTimeline/playSound()[projectSnowFlake_fla.MainTimeline::frame1:275] 在 projectSnowFlake_fla::MainTimeline/playGame()[projectSnowFlake_fla.MainTimeline::frame1:269] 在 projectSnowFlake_fla::MainTimeline/gameLoop()[projectSnowFlake_fla.MainTimeline::frame1:156] [UnloadSWF] projectSnowFlake.swf 测试影片终止。
这是sound:
var sound:Sound = new MainSound();
【问题讨论】:
-
var channel:SoundChannel = sound.play();你的sound变量是什么? -
你得到什么错误?我认为您注册事件的顺序可能是一个问题。但是,除非我查看错误,否则不确定。
标签: actionscript-3 null