LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!
First of all, my thanks to jansschenkel and shadowslash for their help with this but I've come unstuck. Here's an example of how I've tried to set up a player start/stop button with a right click menu option, maybe someone can tell me where I've gone wrong...
start/stop button code:
on mouseUp
if pMouseButton is 1 then -- left-button click
do your normal thing
else
popup button "rightclick"
end if
if the filename of player "p1" is "" then exit mouseUp
put the label of me into myLabel
if myLabel is not "STOP" then
set the label of me to "STOP"
start player "p1"
else
set the label of me to "START"
stop player "p1"
# this resets the player to the beginning
set the currenttime of player "p1" to 0
end if
end mouseUp
on mouseUp mouseButtonNumber
if mouseButtonNumber = 1 then do leftclickstuff
if mouseButtonNumber = 3 then do rightclickstuff
end mouseUp
This looks like a more elegant way to proceed but I do have another question...
Now that I have a pop up menu on my right-click, I am finding it hard to find out how to use the menu items command. If for example I want to have a 'load' option in the menu item list, how do I write the command line to action that menu item?
Thank in advance,
D
So, it's a big Salami... Just take it one slice at a time.
## Only hanlde right clicks!
on mousedown tButton
if tButton = 3 then
popup btn "my context menu" at the mouseloc
end if
end mousedown
## Handle "normal" clicks with the left mousebutton
on mouseup tButton
if tButton <> 1 then
exit mouseup
end if
## do your mouseup stuff here..
end mouseup
To handle the choosen menutitems from the popup you need to do it in the
"menupick" handler of the popup button like this:
on menupick tItem
switch tItem
case "Load"
### do your "load" stuff
break
case "Another choosen menu item"
### do other stuff etc...
break
case "Yet another choosen menu item"
### do other stuff etc...
break
end switch
end menupick
on mouseUp pMouseButton
if pMouseButton = 3 then
popup button "MyPopupButton" at the clickLoc
else
-- do other stuff here
end if
end mouseUp
The popup menu button will receive the 'menuPick' message when the user picks one of the items, so you'll have to move some of your logic into that menu button as well:
on menuPick pItem
switch pItem
case "Hello world"
answer "Hello, world!"
break
case "Foo"
answer "Bar" with "Cancel"
break
-- more case statements here
end switch
end menuPick