Multimedia Programming: Scripting (Lingo)

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 29

Chapter 3 Multimedia Programming: Scripting (Lingo)

Director Basics
Director movies are interactive multimedia pieces that can include animation, sound, text, digital video, and many other types of media. A movie can be as small and simple as an animated logo or as complex as an online chat room or game.

Director divides lengths of time into a series of frames.


When creating and editing movies, you typically work in the four key windows that make up Directors work area:

The Stage is the visible portion of a movie. Use the Stage to determine
where media appears.

the Score , where the movie is assembled


The Score coordinates the movies media, determining when images appear and sounds play. The Score also assigns scripts (Lingo instructions) that specify what the movie does when certain events occur in the movie.

Cast windows , where the movies media elements are assembled

the Control Panel , which controls how the movie plays back

To create a new movie: Choose File > New > Movie.

Movie properties specify properties that affect the entire movie, such as:

how colors are defined the size and location of the Stage the number of channels in the Score copyright information font mapping

Use the Movie > Properties command to set these settings.

Using The Score


The Score organizes and controls a movies content over time in channels. The most important components of the Score are channels, frames, and the playback head. You can also control the Scores appearance using preference settings. To display the Score: Choose Window > Score.

The playback head


The playback head moves through the Score to show what frame is currently displayed on the Stage.

Channels
Channels are the rows in the Score that contain sprites for controlling media. Sprite channels are numbered and contain the sprites that control all the visible media in the movie. Special effects channels at the top of Score contain behaviors as well as controls for the tempo, palettes, transitions, and sounds.

Frames
Frames are represented by the numbers listed horizontally in the sprite and special effects channels. A frame is a single step in the movie.

Setting the number of frames displayed per second sets the movies playback speed.

Sprites
Sprites are objects that control when, where, and how media appears in a movie. The media assigned to sprites are cast members. Creating a Director movie consists of defining: where sprites appear on the Stage when they appear in the movie how they behave what their properties are.

Cast members
Cast members are the media that make up a movie. They can include:
bitmap images text vector shapes sounds Flash movies digital videos

Lingo (Directors scripting language)


Adds interactivity to a movie. Often Lingo accomplishes the same tasks-such as moving sprites on the Stage or playing sounds-that you can accomplish using Directors interface. Lingos usefulness : the flexibility it brings to a movie. Lingo can control the movie in response to specific conditions and events. Behaviors are pre-existing sets of Lingo instructions. Attaching behaviors to sprites and frames lets you add Lingos interactivity without writing Lingo scripts yourself.

Markers
Markers identify fixed locations at a particular frame in a movie. Using Lingo or draggable behaviors, you can instantly move the playback head to any marker frame. This is useful when :

jumping to new scenes from a menu or looping while cast members download from the web. Markers are also useful while authoring to advance quickly to the next scene.
Use the Markers window to write comments associated with markers you set in the Score and to move the playback head to a particular marker.

To create a marker:
Click the markers channel to create a marker. A text insertion point appears to the right of the marker. Type a short name for the marker.

To delete a marker:
Drag the marker up or down and out of the markers channel.

To jump to markers while authoring:


Click the Next and Previous Marker buttons on the left side of the marker channel.

Press the 4 and 6 keys on the numeric keypad to cycle backward and forward
through markers. Choose the name of a marker from the Markers menu.

Editing Frames
To move or delete all the contents of a range of frames:
Double-click and drag in the frame channel to select frames. Choose Edit > Cut or Edit > Copy, or press Delete. If you cut or delete the selected frames, Director removes the frames and closes up the empty space.

To paste copied frames, select any frame and choose Edit > Paste.

To add new frames:


Select a frame in the Score.
Choose Insert > Frames. Enter the number of frames to insert.

Identifying Frames with Lingo


If you are writing scripts, use these Lingo terms to refer to frames in a movie: The function of the frame refers to the current frame. The frame number or the frame marker label refers to a specific frame. The keyword loop refers to the marker at the beginning of the current segment. The word next or previous refers to the next marker or the marker before the current scene, respectively. The term the frame followed by a minus or plus sign and the number of frames before or after the current frame refers to a frame thats a specific number of frames before or after the current frame. For example, theframe - 20 refers to the frame 20 frames before the current frame.

The function marker() with the number of markers used as the parameter refers to the marker thats a specific number of markers before or after the current frame. For example, marker(-1) gives the previous marker. If the frame is marked, marker(0) gives the current frame; if not, marker(0) gives the name of the previous marker. The word movie followed by the movie name refers to the beginning of another movie. For example, movie "Navigation" refers to the beginning of the Navigation movie. The word frame plus a frame identifier, the word of, the word movie, and the movie name refers to a specific frame in another movie; for example, frame 15 of movie "Navigation" refers to frame 15 of the Navigation movie.

Lingo Scripting
When does Lingo run?
When an event occurs, Director generates a message that describes the event. Handlers contain groups of Lingo statements that run when a specific event occurs in a movie. Each handler begins with the word on followed by the message that the handler is set to respond to. The last line of the handler is the word End.

The Lingo language


Lingo terms fall into seven categories: commands instruct a movie to do something while the movie is playing. properties attributes that define an object. functions terms that return a value. keywords reserved words that have a special meaning. events constants elements that dont change. operators terms that calculate a new value from one or more values. A Lingo statement is any valid instruction that Director can execute. An expression is any part of a statement, meant to be taken as a whole, that produces a value. For example, 2 + 2 is an expression but is not a valid statement all by itself. go to frame 23 is a statement go to is the command, and frame 23 is the expression

Lingo supports a variety of data types: references to sprites and cast members, (Boolean) values: TRUE and FALSE , strings, constants, integers, floating-point numbers.

Scripts can use variables to store, update, and retrieve values as the movie plays.
Use the equals operator (=) or the set command to assign values to variables. Use if...then, case, and repeat loop structures to set up statements so that they run when specific conditions exist. Director always executes Lingo statements in a handler starting with the first statement and continuing in order until it reaches the final statement

Dot Syntax
Use dot syntax to express the properties or functions related to an object or to specify a chunk within a text object. Dot syntax expression: name of the object, followed by a period (dot), and then the property, function, or chunk that you want to specify.

For example
The property : the loc sprite property indicates a sprites horizontal and vertical position on the Stage. The expression : sprite(15).loc refers to the loc property of sprite 15. The expression : member("Hot Button").number refers to the cast member number of the Hot Button cast member. Expressing a function : textSpriteObject.pointInHyperlink chunks of text : member("News Items").paragraph(1)

Parentheses
Functions that return values require parentheses. Use parentheses after the keywords sprite or member to identify the objects identifier:

for example, member("Jason Jones-Hughes")

Character spaces
Words within expressions and statements are separated by spaces. Lingo ignores extra spaces. Uppercase and lowercase letters Lingo is not case sensitive

Comments
Comments in scripts are preceded by double hyphens (--). You can place a comment on its own line or after any statement.

Optional keywords and abbreviated commands


You can abbreviate some Lingo statements. Abbreviated versions of a command are easier to enter but may be less readable than the longer versions.

The go command is a good example:


go to frame "This Marker" go to "This Marker" go "This Marker

Literal Values
A literal value is any part of a statement or expression that is to be used exactly as it is, rather than as a variable or a Lingo element.

Literal values character strings, integers, decimal numbers, cast member names, cast member numbers, symbols, and constants.

Each type of literal value has its own rules


Strings are characters that Lingo treats as characters instead of as variables. For example, member ("Greeting").text = "Hello if "Hello Mr. Jones" contains "Hello" then soundHandler put "My thoughts amount to Integers Director works with integers between -2,147,483,648 and +2,147,483,647. (For numbers outside of this range, use floating-point numbers.)

o You can convert a decimal number to an integer by using the integer() function. For example, set theNumber = integer(3.9)
decimal number is what Lingo refers to as a floating-point number. The floatPrecision property controls the number of decimal places used to display these numbers. o You can convert an integer or string to a decimal number by using the float() function. set theNumber = float(3)

Identifying cast members and casts


Lingo refers to a cast member by using the term member followed by a cast member name or number in parentheses.
If more than one cast member has the same name, Director uses the lowest numbered cast member in the lowest numbered cast. For example, the following all refer to cast member 50, which has the name Jason Jones-Hughes:

member("Jason_Jones-Hughes") member(50) member "Jason_Jones-Hughes" member 50 To specify a cast when using member without parentheses, include the term of castLib followed by the casts name or number.

For example, the following statements refer to cast member 50, which is named Jason Jones-Hughes, in castLib 4, which is named Wales Player: member(50, 4) member 50 of castLib 4 member("Jason_Jones-Hughes", 4) member "Jason_Jones-Hughes" of castLib 4 member(50, "Wales_Player") member 50 of castLib "Wales_Player" member("Jason_Jones-Hughes", "Wales_Player") member "Jason_Jones-Hughes" of castLib "Wales_Player"

symbol is a string or other value that begins with the pound sign (#). Symbols are user-defined constants. symbols can usually be performed very quickly, providing more efficient code. For example, userLevel = #novice userLevel = "novice Convert a string to a symbol by using the symbol() function. Convert a symbol back to a string by using the string() function. constant is a named value whose content never changes. For example, TRUE, VOID, and EMPTY are constants because their values are always the same. For example, to test whether the user is pressing the Enter key, use the following statement: if the key = ENTER then beep

Lingo operators
Arithmetic operators (such as +, -, /, and *) Comparison operators (for example, +, >, and >=), which compare two

arguments
Logical operators (not, and, or), which combine simple conditions into compound ones String operators (& and &&), which join strings of characters

Lingo Lists
Lists are basically a set of elements separated by commas. Lingo encloses the set of values in square brackets. A simple example of a list is a list of numbers such as [1, 4, 2]. Lingo can create, retrieve, add to, reorder, sort, or substitute a lists contents.

Director offers two types of lists:


Linear lists In which each element is a single value. For example,
[100, 150, 300, 350]

Property lists In which each element contains two values separated by a


colon. The first value is a property. The second value is the value associated with that property. For example, this list could be a sprites Stage coordinates, with a value for each one: [#left:100, #top:150, #right:300, #bottom:350]

Lingos functions that operate on lists:


display lists (put), find list lengths (count()), find largest and smallest elements in the list (max(), min()), add and delete items in a list (append, add, .....), copy (duplicate()), sort lists.

When the movie first starts, events occur in the following order:
prepareMovie. beginSprite. prepareFrame. startMovie. This event occurs in the first frame that plays.

When Director plays a frame, events occur in this order:


beginSprite. This event occurs only if new sprites begin in the frame. stepFrame. prepareFrame. Immediately after the prepareFrame event, Director plays sounds, draws sprites, and performs any transitions or palette effects. enterFrame. After enterFrame and before exitFrame, Director handles any time delays required by the tempo setting, idle events, and keyboard and mouse events. exitFrame. endSprite. This event occurs only if the playback head exits a sprites in the frame.

When a movie stops, events occur in this order:


endSprite. This event occurs only if sprites currently exist in the movie. stopMovie.

The general order in which messages are sent to objects is as follows:


Messages are sent first to behaviors attached to a sprite involved in the event. Messages are sent next to a script attached to the cast member assigned to the sprite. Messages are then sent to behaviors attached to the current frame. Messages are sent last to movie scripts.

You might also like