Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can i stop a mouseevent in javascript?

function pauseScene(evt:MouseEvent):void
{   
stop();
pause_btn.visible = false;
play_btn.visible = true;
}

I have written the above code in Actionscript to stop a mouse event. Now I want to convert that into Javascript so that the scene in flash cc will be converted to Html5. For that I have used the below code as

function pausescene()
{
 this.stop();
 }

But this is not satisfying my requirement. Please do help me.

like image 777
priyanka Avatar asked Jan 09 '23 14:01

priyanka


2 Answers

event.preventDefault() prevents the default behaviour, but will not stop its propagation to further event listeners.

event.stopPropagation() will not prevent the default behaviour, but it will stop its propagation.

You can use a combination of both.

Example code:

myElement.addEventListener('click', function (event) {
    event.stopPropagation();
    event.preventDefault();

    // do your logics here
});

Reference: https://developer.mozilla.org/en/docs/Web/API/Event/preventDefault https://developer.mozilla.org/en/docs/Web/API/Event/stopPropagation

like image 80
Jack Avatar answered Jan 11 '23 05:01

Jack


If you can capture the event object, you can use the preventDefault() to stop it

function catchMouseEvent(e){
     e.preventDefault();
}
like image 45
uniquerockrz Avatar answered Jan 11 '23 03:01

uniquerockrz