Objects - Behaviors and Properties LiveCode, like many other latest generation languages is based on objects - like buttons, fields, windows, etc. Objects have properties and behaviors. That is to say everything has a description and does things. A chair has properties such as color, size, location, hardness, etc. It also can be used for many things. You can sit in it, stand on it, use it to prop a door opens, etc. In Java, we call them classes/objects and say that they have data (properties) and methods (behaviors). In LiveCode we have many objects. Buttons have properties (color, text label,location, size, etc and they have properties - Click, double click, mouseDown, mouseUp, mouseMove, etc. In this lesson we will program a button to change the properties of another object - a text field. 1. Open up a new stack, and add 2 buttons and a text field. Name the buttons "Red" and "Black". Name the field "mystory" (Notice all the properties while the Property Inspector is open) Click on the second tab of the PI (Property Inspector) and type your story into the "contents" Once you click away from where you are typing, it will show up in that field on screen. We can close the PI for now. We are now going to program the behavior of the first button ("Red"). We will use the mouseUp message. When you click on the mouse messages are sent out to the computer (to your button object) telling it exactly what you did. Some of the messages that originate from a button are: We are going to write a message handler (code) for the mouseUp message.. Click on the "Red" button and click on "Code" icon on the LiveCode toolbar (or right-click on the "Red" button and select "Edit Script") type on mouseUp, then type set the textcolor of field "my story" to red Do the same for the "Black" button, but make it: Now try it out. It should work. For a lesson on the message path and shortcuts for writing code - go to this lesson: |
Home >