Note: This exercise is designed to help you gain a better understanding of LiveCode's message-passing hierarchy. It does not need to be turned in, but I strongly recommend you complete it, as it is fundamental to all we will be doing the rest of the semester.
This exercise is intended to help you understand how messages are passed through the message hierarchy. By understanding this you will be better able to write efficient stacks, because you will know the best place to put handlers that may receive messages from more than one object.
Download a copy of the stack MessageHierarchyEx.rev from the Templates folder on the DigHT 210 server.
Why?
on mouseDown
put "You clicked " & the target into line 1 of field "report"
put "The message handler is in " & the name of me into line 2 of field "report"
end mouseDown
on mouseUp
put empty into field "report"
end mouseUp
Compile and close the button's script. Now click down and hold on button "cardButton". Copy the text that appears in field "report" here:
Click down and hold on each of these objects and observe what happens.
What happens when you click on the fields? Why?
Open the property inspectors for the two fields and check the box "Lock Text". Now click the fields again. What can you conclude about fields and mouse messages?
Open the card's script and paste the handlers into the card script. Compile and close the card script.
Now open all of the other objects' scripts and delete all of the handlers from those objects. Compile and close those scripts.
Click down on button "cardButton". What appears in the "report" field?
Why is it different from what happened in steps three and four above?
Click on the other objects and observe the text that appears there when you click down. Try clicking down on some of the label fields. Also click down somewhere where there is no object (i.e., just click down somewhere on the card that is blank.) Make sure you understand what is happening. Ask the instructor if you don't understand.
Open the card script and copy the handlers. Close the card script and open the script of the group. Paste the handlers into the group's script. Compile and close the script.
Click down on button "cardButton", then click down on button "groupButton". What is difference between the two in terms of what gets put into field "report"?
Try the other objects and observe the result in field "report".
Click down on button "cardButton", then click down on button "groupButton". What is difference between the two in terms of what gets put into field "report"?
Why does nothing happen when you click down on any of the card objects?
Now click down on various objects (and empty places on the card) and observe what happens. What appears in the "report" field?
Why the difference in outcome between steps 7 and 8?