Hi I’m new to as 3.0 and had designed a code which controls the volume by rotating the movie clip which is working absolutely fine. The main problem is that I’m not able to restrict the circular movement of clip between a degree of movement i.e. say between 0[SUP]0[/SUP] to 180[SUP]0[/SUP] degree.
here is the code
import flash.media.SoundTransform;
knob_mc.addEventListener(MouseEvent.MOUSE_DOWN,turn);
stage.addEventListener(MouseEvent.MOUSE_UP,endTurn );
function turn(e:Event):void
{
stage.addEventListener(MouseEvent.MOUSE_MOVE,turn);
var position:Number = Math.atan2(mouseY - knob_mc.y,mouseX - knob_mc.x);
var angle:Number = (position/Math.PI) * 180;
knob_mc.rotation = angle;
if(sndChannel!=null){
var st:SoundTransform = new SoundTransform(normalizeVolume(angle));
sndChannel.soundTransform = st;
}
}
function endTurn(e:MouseEvent):void
{
knob_mc.removeEventListener(MouseEvent.MOUSE_DOWN, turn);
stage.removeEventListener(MouseEvent.MOUSE_MOVE,turn);
knob_mc.addEventListener(MouseEvent.MOUSE_DOWN,turn);
}
function normalizeVolume( angle:Number ):Number
{
angle %= 360;
if (angle < 0)
{
angle = 360 + angle;
}
return percentage(angle,0,360)/100;
}
function percentage( X:Number, minValue:Number, maxValue:Number ):Number
{
return (X - minValue)/(maxValue - minValue) * 100;
}
var soundClip:Sound=new Sound();
var sndChannel:SoundChannel=new SoundChannel();
soundClip.load(new URLRequest("TanhaDil.mp3"));
soundClip.addEventListener(Event.COMPLETE,onComplete,false,0,true);
function onComplete(evt:Event):void {
sndChannel=soundClip.play();
}