Events sent from card to "behave like background" groups
Posted: Mon Oct 20, 2014 5:13 pm
Hi LiveCoders!
I have an issue with mouse events leaking through from one group and triggering handlers in a different group.
In the LiveCode dictionary for `backgroundBehavior` I read:
I want to group a set of controls together, and have a group script handle the mouse actions with the controls within the group. I want this group to appear on more than one card. I want to have more than one group of this kind. I want each group to mind its own business.
However, when I create two groups and place them on two cards, a click on an object in one group sends mouse events to the other group.
I can prevent this by placing dummy mouse event handlers in each object, or on each card. I can also create a switch case in the group script, to ensure that only the controls that are expected to be in that group react to the mouse events that are detected.
All of these workarounds requires hard-coding or placing dummy handlers in inconvenient places. It is an anathema to encapsulation.
What are the LiveCode best practices for dealing with this situation?
EDIT: Here is one solution which must be used in every "on whatever" handler in the group script:
Feature suggestion: perhaps groups with their `backgroundBehavior` property set to true could have a `protectedScript` property; when this is set to true, it would ensure that event handlers in the group script are only triggered if the event was generated within the group itself.
Thanks in advance for your insights,
James
I have an issue with mouse events leaking through from one group and triggering handlers in a different group.
In the LiveCode dictionary for `backgroundBehavior` I read:
It seems therefore that the following behaviour is expected. This is what happens:The group's script is placed behind the card in the message path for any message not originating from a control within it.
I want to group a set of controls together, and have a group script handle the mouse actions with the controls within the group. I want this group to appear on more than one card. I want to have more than one group of this kind. I want each group to mind its own business.
However, when I create two groups and place them on two cards, a click on an object in one group sends mouse events to the other group.
I can prevent this by placing dummy mouse event handlers in each object, or on each card. I can also create a switch case in the group script, to ensure that only the controls that are expected to be in that group react to the mouse events that are detected.
All of these workarounds requires hard-coding or placing dummy handlers in inconvenient places. It is an anathema to encapsulation.
What are the LiveCode best practices for dealing with this situation?
EDIT: Here is one solution which must be used in every "on whatever" handler in the group script:
Code: Select all
on handlerName
get the target
repeat while it is not me
get the owner of it
if it is empty then
exit mouseUp
end if
end repeat
-- Code that only applies to controls in this group
end handlerName
Thanks in advance for your insights,
James