Fix: Flash ChannelState

Monkey Forums/Monkey Bug Reports/Fix: Flash ChannelState

Goodlookinguy(Posted 2012) [#1]
I wanted to get the ChannelState working correctly in flash so that I didn't have to keep timers of how long the sounds have been playing. I'd never written in AS before, but the fix was surprisingly easy. So hopefully this can be added in the next version.

	internal function SoundComplete( ev:Event ):void{
		if( !loop_kludge ) return;
		for( var i:int=0;i<33;++i ){
			var chan:gxtkChannel = channels[i];
			if ( chan.channel != ev.target ) continue;
			
			if ( chan.state == 1 )
			{
				if ( chan.loops )
				{
					chan.channel=chan.sample.sound.play( 0,0,chan.transform );
					chan.channel.addEventListener( Event.SOUND_COMPLETE,SoundComplete );
				}
				else
				{
					chan.state = 0;
				}
			}
			
			break;
		}
	}


	public function ChannelState( channel:int ):int{
		return channels[channel].state;
	}