LOOPE - Lingo Object Oriented Programming Environment by Irv Kalb

Previous Chapter

Table of Contents

Next Chapter

 

Section 3 - Behaviors

Chapter 13 - Behaviors and Objects Working Together

 

So far we have talked about behaviors and objects separately. In this chapter, we will discuss how behaviors and objects can work together to create powerful entities. The general approach will be to create a distributed system. That is, work that can be done at a behavior level is done there, and things that can be done in a centralized location will be accomplished in an object.

A simple analogy would be that the central object is a brain of an animal, and the behaviors are the sense organs. The brain is very sophisticated and can do a great deal of work, but it needs the sense organs to tell it about the world around it. In both cases, the sensors are highly specialized and send messages to the central processor, and the central processor acts on these messages. Sometimes the central processor sends a message back to the sense organ telling it to change its behavior. (If you step on a tack on the floor, your skin tells your brain that you've stepped on something sharp - and the brain in response tells the foot not to step any more until the tack is removed.)

Navigation Manager

Unless you are writing a "one frame movie", you will probably have a need for navigation within and between movies. Navigation is a standard element of Director movies that can be handled very well by a combination of a central object and a number of small behaviors. We will create a single global navigation manager, and a number of small behaviors that we attach to different buttons. These behaviors will send different messages to the Navigation manager. In response, the Navigation manager will send the program to different frames in the current movie or other movies, and keep track of where we have been.

To start, let's design a simple navigation scheme. Assume that we are building a program that has a number of different "significant" frames. We will refer to these frames as "pages", although you may refer to these as screens or scenes or key frames, etc. On each page, there will be a "previous page" button, a field member that always displays the current page number ("n of m" pages), and a "next page" button. Whenever we arrive at a page, clicking on the previous and next buttons should send the user to the appropriate next or previous page. If we are at the first page, the previous button should be unavailable. Similarly, if we are at the last page, the next page button should be unavailable. We also want the ability to go to any page from some main menu (e.g., individual buttons, or a pull down menu). Eventually, we may want an additional slider to allow us to go to any page from any other page.

As an additional requirement/feature, we should be able to have as many labels in the score as we wish, but only be able to navigate to the frames we designate as pages. For example, let's say we named our pages A, B, C, D, etc. we should also be allowed to have additional frames labeled A1, A2, A3, B1, B2, B3, etc. To do this, we need to create a new naming convention. We need to identify the pages that we wish to navigate among, and have a way of distinguishing them from the other labels in the score. As a simple convention, we will add the pound sign "#" to the front of all frames that we wish to be navigation pages. So, we could name our frame #A, #B, #C, etc. Or more likely, we would give these pages more meaningful names like; #Fish, #Bird, #Cat, #Dog, etc. The label names will be useful to the programmer, but will not be evident to the user.

For now, let's just assume a single movie. Later we will expand the code to handle multiple movies. Here is a code fragment that will scan through all the labels in the score and build a list of the page labels:


  plLabels = []
  stringOfLabels = the
labelList
  nLabels = the
number of lines in stringOfLabels
  repeat
with lineNum = 1 to nLabels
    thisLine = line lineNum of stringOfLabels
    if
char 1 of thisLine = "#" then
      append(plLabels, thisLine)
    end
if
  end
repeat

 

This code looks through all the labels in the current movie and builds a list of all labels that begin with a pound sign. These are the only labels that our navigation scheme cares about. We will execute this code when we first enter a movie. .



Previous Chapter

Table of Contents

Next Chapter