Humanities Home page   Office of Digital Humanities
Back     BYU LiveCode Lessons Gateway

DigHT 210

Message Hierarchy Exercise

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.


  1. Click on the various control objects--buttons, fields, graphics. What happens?

    Why?

  2. Enter the following message handlers in the script of button "cardButton".

    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:

  3. Now copy and paste the handlers from button "cardButton" into the other objects' scripts: field "cardField", graphic "cardGraphic", button "groupButton", field "groupField", and graphic "groupGraphic".

    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?

  4. Now cut (do not copy) the handlers from the button "cardButton". Compile and close the empty script.

    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.

  5. 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".

  6. Open the card script and delete both handlers. 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"?

    Why does nothing happen when you click down on any of the card objects?

  7. Open the property inspector for the group "groupedObjectsGrp" and check the box labeled "Behave like a background".

    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?

  8. Think about how your new knowledge of how the LiveCode message hierarchy works can help you program more efficiently.

  9. Make a prediction: What will happen if you remove the handlers from all of the object, card and group scripts and paste them into the stack script?


Back     BYU LiveCode Lessons Gateway
Maintained by Devin Asay.
Copyright © 2005 Brigham Young University