September 06, 2006
AS3 volume control voodoo
While working with the AS3 sound controls this week, I've run into a few snags.
1. Despite what the Adobe docs say, SoundTransform.volume is NOT a writeable property. You have to create a completely new SoundTransform object with your desired volume and pan settings, and then ASSIGN that SoundTransform to the desired SoundChannel.soundTransform property to get it to change. Why?
2. If I fade the volume up from zero to 1 in increments of 0.01, it stops at 0.06. If I fade in increments of 0.005, it never goes up at all. If I fade in increments of 0.0101, it fades all the way up. So it looks like you can't reliably adjust the volume by 0.01 or less. Weird.
Posted by andy at September 6, 2006 12:13 PMvolume is writable, but is not watched for changes. This is the same with many other similar objects in AS3 (and even AS2) like filters. You can't just change a property of a filter. you have to reassign the whole filters array for the object to react to the change. Same with the other transforms such as ColorTransform. It would be impractical for an object to listen for changes on every single property of every filter, transform object, etc. You don't have to create a new SoundTransform. Just grab a ref to it, change the volume and pass back the ref.
As for #2, that is a bit odd. it may be stored as some other number, like alpha is stored as 255 values despite being represented by numbers from 0.0 to 1.0.