Multimedia Programming
Basic Lingo
Programming Interactivity

  1. Types of interactivity.

    1. Buttons (or sprites used as buttons). Click on the button to achieve some result.

      1. Events: mouseUp, mouseDown.

      2. Normally this is placed in either a sprite script or a cast script. If the button has different reactions in different frames, then place the script in the sprite. If the button always reacts the same way (or is used only in one frame), then put the script in the cast.

      3. Example:

        		on mouseUp
        			go to frame "part 2"
        		end
        

    2. Fields. Used to allow user to enter information.

      1. To get information from a field, use a script like:

        put field "Name" into theName

        where theName is either a local or global variable. You could also store the value in a field into another field.

      2. You can also get information as soon as it is entered into the field by using a on keyUp handler that is placed in either the sprite or cast script for the field. In this case you should test for a specific key, like the RETURN key.

      3. To determine which key was hit by the user, use the function the key which returns the value of the last key entered.

      4. Example:

        		on keyUp
        			global theName
        
        			if the key = RETURN then	
        				put field "Name Entry" into theName
        			end if
        		end keyUp
        

    3. Check boxes and radio buttons. These are types of buttons. You can determine whether a check box is "checked" by testing it's hilite property. If this property is true, then the button is "checked". If the property is false, then the button is not "checked".

      		if the hilite of member "Choose Option" = TRUE then
      			go to frame "new sequence"
      		end if
      

    4. Entering a sprite. You can achieve interactivity by noticing when the cursor enters a sprite.

      1. Do this with the "rollover(x)" function.

      2. Normally this is placed in an exitFrame script.

        		on exitFrame
        			if rollover(1) then go to frame "Left"
        			if rollover(2) then go to frame "Right"
        		end
        

    5. Changing cursor. It is often appropriate to change the design of the cursor when the cursor is over a sprite. This tells the user that something different has happened.

      1. You can use built in cursors or custom cursors that you make yourself.

      2. 2. If you use a custom cursor, it must be 1-bit and must be no larger than 16X16 pixels.

      3. Example:

        		on exitFrame
        			if rollover(1) then
        				cursor [3]
        			else 
        				cursor -1
        		end
        

      4. Note that using a number without brackets in the cursor command will cause director to use a built-in cursor. Using a number in brackets will cause director to look in that numbered cast member.

      5. Since a cursor is 1-bit, it is either black or white. White areas will appear transparent on the stage. To make them opaque, you must create a mask. The mask looks exactly like the cursor, except it is black in the areas that you want to appear opaque.

      6. Example:

        		on exitFrame
        			if rollover(1) then
        				cursor [3,4]
        			else 
        				cursor -1
        		end
        

      7. In this example, the cursor is in cast member 3, the mask in cast member 4.

    6. Custom cursors. You can make any sprite a cursor by turning the normal cursor invisible and making the sprite follow the location of the cursor. Note that this works best if your custom cursor is small with few colors (e.g., 8 bits at the most). If the cursor is too large or too colorfull, it will take Director too long to redraw it and there will be a lag as you move the cursor.

      To create a custom cursor (which I assume is in sprite 5), follow the two steps below:

      1. make the normal cursor invisible and make your sprite a puppet. You could do this in the movie script:

        	on startMovie
        		set the puppet of sprite 5 to TRUE
        		cursor 200
        	end
        

      2. Now make your custom cursor follow the old cursor by calling the user-defined handler doArrow . We'll define this handler in a minute.

        	on exitFrame
        		doArrow
        		go to the Frame
        	end
        

      3. In this case you must create the handler doArrow . Put this in the movie script:

        	on doArrow
        		set the locH of sprite 5 to the mouseH
        		set the locV of sprite 5 to the mouseV
        		updateStage
        	end
        

    7. Key input. You may want special keys to mean something throughout the movie. For example, you may want the right and left arrow keys to always mean "go to the next page".

      1. You will use the keyUp handler to achieve this interactivity.

      2. Often it is best to use a primary event handler to catch this message. For example, the keyUpScript and keyDownScript are good places to catch a keystroke that you want to always be caught in the movie.

      3. Example:

        		on startMovie
        			set the keyUpScript to "checkForTab"
        		end
        

        on checkForTab if the key = TAB go next end

        the checkForArrow is a name of a handler that you must place in the movie script.

      4. Primary event handlers are tricky to program.

      5. As an alternative, you can catch the key stroke in a movie script. This is easier to program. Since the movie script is at the top of the message hierarchy, a key stroke will always be caught.

      6. Example: in a movie script put the following:

        	on keyUp
        		if the key = TAB then go next
        	end
        

        7. Note that the TAB used here is a predefined constant. That means that director already knows about it....you don't have to assign a value to it. The predefined constants in director a re:

        	BACKSPACE	EMPTY	ENTER	FALSE	QUOTE
        

        RETURN TAB TRUE

        8. To check for any other character, youÕll have to know its ASCII encoding.

    8. Moving sprites. Often you can make a sprite moveable and let the user move the sprite over another sprite. For example, an arrow sprite can be moveable. When the user movies the arrow over one of three boxes, you go to the corresponding frame.

      1. To make a sprite moveable, you can either check its moveable box in the score, or you can make it moveable via Lingo.

      2. If you use Lingo, you must determine in which frames the sprite will be moved. If it is to be moved in all frames in the movie, make it moveable in the startMovie script:

        		on startMovie
        			set the moveableSprite of sprite 2 to TRUE
        		end
        

      3. If the sprite is only to be moved in a particular frame, make it moveable when you enter the frame and unmovable when you exit:

        		on enterFrame
        			set the moveableSprite of sprite 2 to TRUE
        		end
        

        on exitFrame set the moveableSprite of sprite 2 to FALSE end

      4. You can then determine whether the user has moved the sprite over another sprite using either the intersects or the within tests.

      5. Example:

        	on exitFrame
        		if sprite 2 intersects 4 then go to frame ÒanimateÓ
        	end
        

    9. Menus. You can create custom menus for your movies using Lingo.

      1. There are two parts to this. First, you must create the menu. This can be done anywhere. If you want the menu to last the whole movie, put it in the startMovie script. If you want the menu only to be present in a particular frame, put it in the enterFrame script.

      2. To create the menu use the installMenu command:

        	on startMovie
        		installMenu 17
        	end
        

        where 17 is the number of the field cast member that contains the menu's items and their definitions. Note that you must use the cast number, not a name.

      3. You must create a field and place the information for the menu in the field. For example, the field in cast 17 might contain the information:

        	menu:Volume
        	Loud|go to frame "Loud"
        	Medium|go to frame "Medium"
        	Soft|to to frame "Soft"
        

      4. You can put more than one menu into a menubar.

      5. You remove a menu with the command:

        	on startMovie
        		installMenu 0
        	end
        

  2. Making Decisions. If you are going to have any type of sophisticated decision making, you must make decisions.

    1. Decisions can be based on user input (such as entering values in a field), or they can be based on information that your scripts maintain (in a global variable) or they can be made based on what's happening on the stage (e.g., when sprites intersect).

    2. The principal means of making a decision is through an if-then-else statement. The syntax is:

      	if boolean-expression then
      		some Lingo commands
      	else
      		some other Lingo commands
      	end if
      

    3. Example: User enters a value in a field. In this case you must get the value from the field and then test it. There are two cases:

      1. You test the value when the user hits the return key. In this case, you could put a

      2. You loop in the frame, testing the value in the field each time you exit the loop.

    4. Other types of Lingo Control.

      1. Repeat structures. Repeat structures can be used for many different effects in Lingo. Remember that other types of interactivity cannot
      2. One example: printing the mouse location.

      3. Controlling sound.

      4. Controlling the tempo.

      5. Playing Video.

      6. Controlling palettes.

    Return to Student Home Page

    Last Modified: 6 April 1998

    THIS PAGE MAINTAINED BY:
    John Barr, Ithaca College