priyanka
priyanka

Reputation: 197

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.

Upvotes: 4

Views: 8018

Answers (2)

Jack
Jack

Reputation: 1769

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

Upvotes: 9

uniquerockrz
uniquerockrz

Reputation: 231

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

function catchMouseEvent(e){
     e.preventDefault();
}

Upvotes: 1

Related Questions