![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
Lingo basics-- exercise II, March 15, 2000 -- |
||||||
![]() |
||||||
Contents |
I. Controlling navigation. |
|||||
![]() |
||||||
|
||||||
![]() |
||||||
Introduction |
This module looks at basic text input and output in Lingo. The main data type for text manipulation is the text field. This is a fairly versatile structure with several useful Lingo primitives for user interaction with text data. |
|||||
![]() |
||||||
Structure |
The image and the text field for the alien greeting are constructed in advance. The text field is set to contain the greeting phrase, with generic placeholder words for the name and S.O. type. The playback of the movie loops in one single frame. When the movie starts, the sprites containing the greeting image and text field are made invisible. The Greet button is given a sprite handler that is called when the user clicks the mouse on the button. The handler replaces the placeholder words in the greeting text field with the current contents of the name and S.O. type fields. Then, it makes the image and text field of the greeting visible. Watch out for the case where the user types more than one word in one of the input fields! To make sure that the word substitution works correctly, you may want to reset the contents of the greeting text field every time before word substitution. |
|||||
![]() |
||||||
Relevant Lingo |
A cast member of the text field type can be manipulated quite flexibly from Lingo code. Here are a few primitives you will need for this exercise. the text of member. Contains the full text currently stored in the field. word <number> of line <number> of member. A way of specifying a single word in a multi-line text field. put <something> into <container>. Used to put text strings into text fields or strings. &. String concatenation. For example, here is a line from the handler that substitutes the placeholder words in the greeting text field with what is currently in the name and S.O. type fields. put (the text of member "nameField" & ".")into-> word 2 of line 1 of member "greetingsField" (The symbol "->" is not part of the Lingo code. It means that all of the above should really be on one line in the Script window.) the visible of sprite. A property that has the values TRUE and FALSE. Can be tested and set in Lingo code. on startMovie. A handler that you put in a movie script. It is called when the movie starts playing. Note: It might be tricky to create a movie script. A safe way is to open the Script window from the Window menu, click the plus sign to create a new script, click the info ("i") icon and set the type to Movie in the Type menu of the Cast Member Properties dialog. |
|||||
![]() |
||||||
Defining your own handlers |
You may find that it is a good idea to reset the greeting text field every time you want to to do a new substitution (i.e., every time the user clicks the Greet button). You also need to reset the field when the movie starts. This calls for a handler of your own, that you can call both from the startMovie handler and the Greet button mouseUp handler. What you do is to write a new handler in the movie script, that responds to an event that we might call resetGreetings: on resetGreetings put "Greetings, <name>" into -> line 1 of member "greetingsField" put "How is your <sotype>" into -> line 2 of member "greetingsField" end resetGreetings (Note the "->" symbols again. The whole put statement should be on one line in the Script window.) Now you can call the resetGreetings handler whenever you want. For example, your startMovie handler may look like this: on startMovie set the visible of sprite 12 to FALSE set the visible of sprite 13 to FALSE resetGreetings end startMovie (Provided that your greetings image and text field are in sprites 12 and 13.)
|
|||||