package classes.gustavo.midia.player
{
	
	import flash.display.*;
	import flash.events.*;
	import flash.geom.*;
	import flash.media.*;
	
	
	public class Volume extends Sprite
	{
		
		private var barraMenor			:MovieClip;
		private var barraMaior			:MovieClip;
		private var limite				:Rectangle;
		private var volume				:Number;
		private var chanel				:SoundChannel;
		
		public function Volume() 
		{
			
			barraMaior 	= _barraMaior_mc;
			barraMenor 	= _barraMenor_mc;
			limite 		= new Rectangle(barraMaior.x,0, barraMaior.width-barraMenor.width,0);
			
			addEventControl();
			
		}
		
		
		private function addEventControl():void
		{
			barraMenor.buttonMode = true;
			barraMenor.stage.addEventListener(MouseEvent.MOUSE_DOWN,  segura);
			barraMenor.stage.addEventListener(MouseEvent.MOUSE_UP,	solta);

			
		}
		
		private function segura(e:MouseEvent):void 
		{
			barraMenor.startDrag(false, limite);
			this.addEventListener(Event.ENTER_FRAME, updateVolume);
		}
	
		private function solta(e:MouseEvent):void 
		{
			barraMenor.stopDrag();
			this.removeEventListener(Event.ENTER_FRAME, updateVolume);
		}
		
			
		private function updateVolume(e:Event=null):void 
		{
		
			var volumePorcento:Number;
			var transformacao:SoundTransform;
			
			transformacao  		 =  getChanel.soundTransform; 	
			volumePorcento 		 = (barraMenor.x - barraMaior.x) / (barraMaior.width - barraMenor.width);
			
			transformacao.volume = -(volumePorcento - 1);
			
			if (transformacao.volume > 1)
			transformacao.volume = 1;
			
			if (transformacao.volume < 0 )
			transformacao.volume = 0;	
			
			getChanel.soundTransform = transformacao;
			
		}
		
		public function set setChanel(_chanel:SoundChannel):void
		{
			
			chanel = _chanel;

			return void;
			
		}
		
		
		private function get getChanel():SoundChannel
		{
			
			return chanel;
			
		}
		
		
	}//end class

}