Thursday, July 20, 2006

Regular.easeOut the sound, please!

This might be the first concrete piece of code I've posted here. While finding myself writing a sound fade routine for the 100th time over again, I decided that I need to take action and finally add another class to the utils package. First I thought I'd go with the old setInterval thing and just stick it in there. But then I thought about the Tween class. And of implicit getters and setters. And if the getting/setting would work with the array access operator that Tween uses.
Well it works.
So without further due I give you the sound volume tween class:

import mx.transitions.Tween;
import mx.transitions.easing.*;

class utils.sound.ExtendedSound extends Sound
public function addEventListener() {};
public function removeEventListener() {};
private function dispatchEvent() {};
private function dispatchQueue() {};

private var __sndVolume: Number;
private var sndTween: Tween;

public function get sndVolume(): Number
__sndVolume = getVolume();
return __sndVolume;

public function set sndVolume(inVol: Number): Void
__sndVolume = inVol;

* @usage: var snd = new ExtendedSound(someMovieClip); snd.fadeTo(25, 3);
public function ExtendedSound(_args)
trace(toString()+'.NEW > ');

public function toString(): String
return 'utils.sound.ExtendedSound';

public function onFadeFinished():Void
trace(toString()+'.onFadeFinished > ');
dispatchEvent({target: this, type:"onFadeFinished"});

public function fadeTo(inTargetVol: Number, inDuration: Number)
if(inTargetVol == sndVolume){
inTargetVol = (inTargetVol < intargetvol =" (inTargetVol"> 100) ? (100) : (inTargetVol);

sndTween = new Tween(this, "sndVolume", Regular.easeOut, sndVolume, inTargetVol, inDuration, true);
var _this = this;
sndTween.onMotionFinished = function(){


Post a Comment

Links to this post:

Create a Link

<< Home