2013-08-21 87 views
0

因此,继承人的代码:AS3空对象引用

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); ,但我不在一开始把它作为一个游戏运行一段时间没有错误,因此Im提示在onComplete函数或事件监听器中存在问题,但是,我尝试的所有尝试都失败了,现在我在这里呆了一段时间。

我只是决定在这里发布,看看是否有人能看到问题。

在此先感谢!编辑: 对不起,我还没有包括这个马上。

错误:

TypeError: Error #1009: Cannot access a property or method of a null object reference. at projectSnowFlake_fla::MainTimeline/playSound()[projectSnowFlake_fla.MainTimeline::frame1:275] at projectSnowFlake_fla::MainTimeline/playGame()[projectSnowFlake_fla.MainTimeline::frame1:269] at projectSnowFlake_fla::MainTimeline/gameLoop()[projectSnowFlake_fla.MainTimeline::frame1:156] [UnloadSWF] projectSnowFlake.swf Test Movie terminated.

而且继承人的sound

var sound:Sound = new MainSound(); 
+1

'VAR渠道:的SoundChannel = sound.play();'你是什么'sound'变量? –

+0

你会得到什么错误?我在想,你注册事件的顺序可能是一个问题。但是,不知道,除非我看错误。 – Zeus

+0

看到最后编辑 – Dominiko

回答

0

我看了你的代码,唯一的潜在问题是声音变量,可以为空。

你是否实例化了声音变量?

如果声音有价值,方法播放(可变声音)可以返回空值?

编辑点评AFTER:

嗨,鉴于thisthis issue

+0

看到最后编辑 – Dominiko

+0

嗨,你测试了方法play()的结果吗?它可能返回null? –

+0

刚刚做到了,这可能是一个问题,它返回undefined – Dominiko