PDA

View Full Version : SoundChannel null issue



jaxz
May 4th, 2009, 06:06 AM
SoundChannel null issue
In my code I frequently call a volume adjusting function where I assign new volumes to all soundchannels in use with a simple command.
The error I encounter comes when I call this function before all soundChannels have been initiated with an actual sound.

The critical part of my code is this:



var themetransform:SoundTransform = new SoundTransform(setVol);
if (SC_B != null); {

SC_B.soundTransform = themetransform; // Causes Error
}

I get an error saying “can’t access null object” or similar – and this follows after my check if the SC_B is null.
This issue only arises early in the execution of my project, that is before SC_B has been assigned to a sound_B.play() instance.
Is there any other way than comparing to null as above that I can use to prevent this error?

Please advice,

Jaxz :hr:

IQAndreas
May 4th, 2009, 10:11 AM
You need to make sure "SC_B.soundTransform" isn't null as well.

That, or I noticed a little semicolon after the if which is likely giving you your woes.

You look through your entire code, thinking it is perfect. No typos in site, yet it is somewhere there, hiding in plain sight, yet still impossible to sea.

jaxz
May 5th, 2009, 07:03 AM
thanks bunches - the semicolons did it...
Cheers,
jaxz