Search code examples
actionscript-3flash-cs3

how to make a volume button follow mouse when clicked only


I was making a simple sound player so i thought that it should also have volume control

so i made a volume button

and added to it Mouse_Down event but it was only listened to once, i am confused that how should i detect the event again and again, if i get that i will write the code something like this in the event //the numbers in code will not be same if i right it in the actual script

if !(button.x<400&&button.x>300)
{
button.x=MouseX
button.y=232
}

Solution

  • Use MOUSE_MOVE and check also buttonDown property in MouseEvent

    ex:

    stage.addEventListener( MouseEvent.MOUSE_MOVE, moveHandler );
    function moveHandler(e:MouseEvent):void 
    {
        if(e.buttonDown)
        {
        //do something
        }
    }