Archive for September, 2008

Soundcard check

Tuesday, September 16th, 2008


To check if the soundcard is available, test if the SoundChannel class is not null

var sound:Sound = new Sound();
var channel:SoundChannel = sound.play();
 
if(channel != null){
    trace("Soundcard available");
}else{
    trace("Soundcard not available");
}

numberLoop

Wednesday, September 3rd, 2008


Here is a method that I use a lot when I need to loop a length of any kind

trace(numberLoop(103754, 3));
//2
 
trace(numberLoop(686.9384, 17.53));
//3.268399999999957
 
trace(numberLoop(Math.PI*13/6, Math.PI*2));
//0.5235987755982991 rad - radToDegree == 0.5235987755982991*180/Math.PI -> 30.000000000000014º
 
trace(numberLoop(-2187.4, 2));
//0.599999999999909
 
function numberLoop(n:Number, t:Number):Number {
	if(t<=0){
		throw new Error("Total must be greater thant 0");
	}
 
	return (n%t+t)%t;
}