0
votes

So heres the code:

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();
}

I get the error on channel.addEventListener(Event.SOUND_COMPLETE, onComplete); but I dont get it at the start, as a game runs for some time without the error, so Im suggesting theres a problem in a onComplete function or an event listener, however, all I tried had failed and Im stuck here for some time now.

I just decided to post it here and see if anybody can see the problem.

Thanks in advance!

EDIT: Sorry I havent included this right away.

Error:

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.

And heres the sound :

var sound:Sound = new MainSound();
1
var channel:SoundChannel = sound.play(); what is your sound variable? - Simon Forsberg
What error do you get? I'm thinking that the order in which you have registered the event could be a problem. But, not sure unless I look at the error. - Zeus

1 Answers

0
votes

I read your code, the only potentially issue is sound variable, can be null.

Have you instantiated sound variable?

If sound is valued, the method play (of variable sound) can return a null value?

EDIT AFTER COMMENTS:

Hi, view this and this issue