JSUI on mouse up?
Hi, I am trying to implement a simple GUI button in Mgraphics, the button changes colour depending on whether the mouse hovers over it of if it is clicked.
I'm using 'onclick()' to change the button to it's clicked colour when the mouse is down. I'd like to be able to change back to the hover colour when the mouse is released.
I've tried using 'onidle()' and 'ondrag()' for this but I have to move the mouse after releasing the click for those to be called.
Is there any hidden 'onmouseup()' function not mentioned in the documentation, or is it possible to roll my own?
Any help would be much appreciated.
For anyone interested I think I found the solution to this problem.
Putting a call to 'ondrag()' inside 'onclick()' and then doing all of my hit detection inside 'ondrag()'.
You can also check to see if the button is pressed in 'ondrag'. If not, it's really a 'onrelease' event in disguise.
I was trying to figure this out and came up with something.
I simply wanted a bang on mouse down and bang mouse up to go out an outlet in the JSUI object.
I don't know Javascript and I'm learning as I go so let me know if I've done something horribly wrong. It works so I don't think there's an issue.
The formal parameter in this function is "but" (I copied it from a reference example) which I assume stands for button.
Inside your ondrag() function just place this code along with any other ondrag stuff. I put it at the end.
add the "but" to the ondrag() function ondrag(x,y,but,cmd,shift,capslock,option,ctrl)
if (but == 0) {
outlet(2, 1)
}
else {
outlet(null,null)
}
Apparently the ondrag() function can detect up or down button presses so I just had it detect if the button was "not pressed" or "0" and send a 1 to use as a bang. Otherwise send null out null port.
Couldn't find another answer on here so when I figured out a method I thought I'd give back some to the community ;)