Monday, December 7, 2009

SoundTransform, Sound objects AS3 help

Another great gotcha, my aim here is to save someone a few min. banging your head against the keyboard wondering why your SoundTransform is not working with the Sound Object in as3. So the logical way to apply a sound transform, imo, would be to apply it BEFORE the soundChannel gets applied the sound object, thus starting the playback.

But of course, it works the other way around....

Apply the Sound Transform to the soundChannel object associated with the Sound Object AFTER the play function,. like so :

private var sc:SoundChannel = new SoundChannel();
private var req:URLRequest = new URLRequest("someSound.mp3");
public var bk_music:Sound = new Sound(req);

function startMusic():void {

var transform:SoundTransform = new SoundTransform(.2, 0);
// sc.soundTransform = transform; ////THIS IS INCORRECT, DOH !
sc = bk_music.play();
sc.soundTransform = transform; /// correct placement of soundTransform... :}
}

This only wasted about 45min of my life,....just the op order of the soundTransform object.
Hope someone else saves some time when they finally get to this post...



btw: in case anyone is wondering how to start /stop their sound after getting the soundTransform to work, add some eventlisteners and control the soundChannel object very simply :

public function quietMusic():void {
sc.stop();
}
public function loudMusic():void {
sc = bk_music.play();
}


enjoy, frustrated flashers!