Skip to main content
Cap Prince
Participant
December 20, 2020
Answered

Right Mousedown + Left Mousedown Triggers event and Right Mouse Down Triggers a different event

  • December 20, 2020
  • 2 replies
  • 834 views

Hi Everyone-

 

I am up against a wall on this conversion project from AS3 to CreateJS.  

 

Scenario:

When the user Right MouseDowns on an object it displays an "Action Window".  However, when the use Left MouseDowns on the object and then Right MouseDowns it displays a different "Information Window".  It works great.  ONCE!

 

When the user colpetes both the Right Event and the Left/Right event ONLY the Left/Right Event will fire.  The Right only event will not.

 

I have tried it different ways to make it work and the other attempt that somewhat worked was similar to the above however, the Information Window would appear with the Action Window.

 

Any help is appreciated as I have been hobbling code to convert a massive amount of flash this year and I am down to two pieces that are tripping me up.  For the record, I am NOT a coder (so my approach may be janky) but it fell into my lap at work. Below is the code:

 

var _this = this;
 
//left click
 
_this.scene3501.on("mousedown", function (evt) {
var e = evt.nativeEvent;
var key = e.which || e.keyCode;
if (key === 1) {
_this.scene3501.gotoAndStop('selected');
_this.t22.gotoAndStop('on');
_this.wp.gotoAndStop('on');
console.log('left');
actionToggle1 = true
console.log('actionToggle1')
_this.scene3501.on("mousedown", leftrightClick3501); 
 
}
});
 
function leftrightClick3501(evt){
var e = evt.nativeEvent;
var key = e.which || e.keyCode;
if ((key !== 1) && (actionToggle1 == true)) {
_this.infoMenu.visible=false
console.log('Leftright');
_this.actionMenu.visible = true
actionToggle1=false
_this.scene3501.removeEventListener("click", rightClick3501);
} else {
console.log ('didnt work')
}
}
 
//right click alone
_this.scene3501.addEventListener("click", rightClick3501); 
 
function rightClick3501(evt){
var e = evt.nativeEvent;
var key = e.which || e.keyCode;
if (key !== 1) {
actionToggle1 = false
console.log('rightONLYscene3501');
_this.infoMenu.gotoAndStop('scene3501')
_this.infoMenu.alpha=100
_this.infoMenu.visible=true
}
_this.infoMenu.x = _this.infoMenu.x = 530
_this.infoMenu.y = _this.infoMenu.y = 200 
// _this.scene3501.removeEventListener("click", leftrightClick3501);
}

 

What is the best way to reset the event listeners?

 

    This topic has been closed for replies.
    Correct answer kglad


    this.scene3501.addEventListener("mousedown",downF.bind(this));

    function downF(e){
    if(this.previousClick==1 && e.nativeEvent.which==3){
    leftRightF.bind(this)();
    } else if(e.nativeEvent.which==1){
    leftF.bind(this)();
    }
    this.previousClick = e.nativeEvent.which;
    }

    2 replies

    Legend
    December 20, 2020

    "When the user Right MouseDowns on an object it displays an "Action Window".  However, when the use Left MouseDowns on the object and then Right MouseDowns it displays a different "Information Window"."

     

    Hold up. You're saying that if the user right-clicks on a symbol they get a context menu, but if they right-click, having previously left-clicked, they get something else? In all my decades of software use, I don't think I've ever encountered any UI convention like that. It sounds like something out of a fighting game. It sounds, from both a usability and discoverability perspective, pretty terrible.

     

    Why don't you just combine the two into a single dialog? Or show the info dialog on right click, with a button at the bottom to display the actions? Or vice versa? This would keep the number of required mouse clicks the same, but be enormously simpler for users to understand.

    Cap Prince
    Participant
    December 20, 2020

    HI ClayUUID-

     

    If I could do it any other way than I stated I would have.  And I agree with your assessment, however, again this is how the file was build in AS3 for which I have been tasked with converting to CreateJS. 

     

    Now I don't feel as bad as I did not getting this to work.  Either way, I have to get it to work as the original (not even going to get into InputText in an Animated MC).

     

    Thank you,

     

    Cap

     

     

     

    kglad
    Community Expert
    kgladCommunity ExpertCorrect answer
    Community Expert
    December 20, 2020


    this.scene3501.addEventListener("mousedown",downF.bind(this));

    function downF(e){
    if(this.previousClick==1 && e.nativeEvent.which==3){
    leftRightF.bind(this)();
    } else if(e.nativeEvent.which==1){
    leftF.bind(this)();
    }
    this.previousClick = e.nativeEvent.which;
    }

    Cap Prince
    Participant
    December 20, 2020

    Hi kglad,

     

    Thank you.  I will try and get back to you.

     

    Cap

    kglad
    Community Expert
    Community Expert
    December 21, 2020

    sounds good.