Useful Lingo by Matt Ottewill

Introduction

Lingo is Director's powerful and mature object orientated scripting language. It's concepts and uses are accessible to non-programmers with a little practise, allowing them to build powerful interactive applications and web sites.

Assigning scripts to run from keyboard keys

Director has a Key Down function which you can write into a prepareMovie or startMovie script or attach to a field text sprite.

on keyDown
if the key = "q" then play movie "quit"
if the key = "s" then go to frame 1
end if
end keyDown

Allowing only some keys to work

You can also allow only specific characters to be entered into a text field. In the following example script (which was attached to a text field in a calculator) only number and backspace keys will function.

on keyDown
if ("0123456789" contains the key or the key = BACKSPACE) then
pass
else
stopEvent
end if
end

download icon Calculator tutorial movie (.dir)

Need help downloading this file?

PreLoad scripts

preLoad scripts allow you to ensure that cast members are in RAM and ready to playback (or be viewed) immediately. This prevents glitches in performance. You can put preLoad scripts in 3 places ...

prepareMovie handlers

startMovie handlers

frame scripts

I prefer to put preload scripts on exitFrame handlers because it allows you to have some text on screen which says something like "Loading media ..."

Examples

To preLoad all cast members in a movie ...

on prepareMovie
preLoadMember()

end
or ...
on enterFrame
preLoadMember()
end

To preload a single cast member ...

on enterFrame
member("cat image").preload()
end
or ...
on enterFrame
preLoadMember "cat image"
end

To preLoad all cast members from the current frame to the end of the timeline ...

on enterFrame
preLoad()
end

To preLoad all cast members on the timeline between the frames 10 and 44 ...

on enterFrame
preload 10, 44
end

The following are old (Pre MX) Lingo syntax but should still work. These will preload all cast members from cast cell locations 10 to 44 ...

on prepareMovie
preloadmember member 10, 44
end
or ...
on enterFrame
preloadmember member 10, 44
end

Repeat with loops

Repeat with loops offer a way to apply the same script to a number of sprite channels automatically. The following script turns off sprite channels 23 to 78.

repeat with channel = 23 to 78
sprite(channel).visible = FALSE
end repeat

Repeat while loops

Repeat while loops offer a way of ensuring that something continues to happen whilst a condition is being met. The following script ensures that the computer will emit an audio beep whilst the mouse is held down.

on mouseDown
repeat while the STILLDOWN = TRUE
beep
end repeat
end mouseDown

download icon Repeat while loop/Timer movie (.dir)
download icon Repeat with loop/Timer movie (.dir)

Need help downloading this file?

Constraining sprites

To constrain the movements of one sprite to the borders of another ...

sprite(1).constraint = 2

The following scrip can be used to restrict the horizontal movement of one sprite (2) to the boundaries of another (1) and the horizontal position of the mouse. Ideal for an audio fader where (2) is the fader knob and (1) the fader track. The following script could be attached to the fader knob (2).

on mouseDown
repeat while the STILLDOWN = TRUE
sprite(2).locH = constrainH(1, the mouseH)
updateStage
end repeat
end mouseDown

download icon Spinning disc tutorial movie (.dir)

Need help downloading this file?

See also Lingo & Sound.

Changing the cast member of a sprite

This script exchanges a cast member in channel 1 of the score. As well as by name, cast members may also be referred to by their cell number position in a cast.

if sprite(1).member = member "Image 1" then
sprite(1).member = member "image 2"
end if

Controlling the "visible" of a sprite

This script turns a channel in the score off, thus rendering any cast members in that channel invisible.

sprite(5).visible = FALSE

This script turns a channel in the score on.

sprite(5).visible = TRUE

You can use a prepareMovie handler to set the initial condition.

Intersect function

An apparently undocumented function. I don't know if this means it will behave erratically on some systems but it's always worked for me. Very useful!

if sprite 11 intersects sprite 12 then set the stagecolor = random(256)

download icon Interaction 1 tutorial movie (.dir)

Need help downloading this file?

Paths & folders

You can make a projector look for and load a movie in a separate folder by using the following syntax ...

on enterFrame
go to movie "@:movies:menu"
end enterFrame

... where "movies" is the name of a folder on the same level as your projector, and "menu" is the name of a movie inside that folder.

Web links

To open a browser and go to a web site ...

on mouseUp
goToNetPage "http://www.somesite.com"
end mouseUp

Mailto scripts

You can open an end-users email client, address and create a new message and complete the subject line with the following script.

gotoNetPage "mailto:myname@myplace.com?subject=put the subject of the email here&cc= myotherfriend@hisplace.com&bcc= mysecondfriend@herplace.com"

This script works by opening an end-users browser and then launching the default email client set in the browsers preferences. If no browser is installed, or no email client is set in the browsers preferences, the script won't work. Nevertheless, this is usually a fairly reliable method given that most browser installations (IE) will pre-configure an email client (Outlook Express) in their preferences.

Opening another application

The open function allows you to open a file into an application. For example, you may have some pdf files in your media folder and want to open them into Acrobat from Director.

on mouseUp

if the platform contains "Mac" then
open the moviePath&"media:pdfs:mypdf.pdf" with the moviePath&"media:pdfs:Acrobat Reader 5.0"

else

if the platform contains "Windows" then
open the moviePath&"@:media:pdfs:mypdf.pdf" with the moviePath&"@:media:pdfs:Acrobat Reader 5.0"
end if
end if
end

You will need your target pdf next to a copy of Acrobat Reader in a suitably named folder (we used a folder called “pdfs” inside a folder called “media” on the same level as the movie).

WARNING!!! This works well on Macs but I haven't checked this on a windows machine yet. This syntax may work better ...

else

if the platform contains "Windows" then
open the moviePath&"media:pdfs:soundcard.pdf" with the moviePath&"media:pdfs:Acrobat Reader 5.0"
end if

QuickTime Lingo

Click here for help with QuickTime Lingo.

MIAWs (movie in a window)

Having multiple movies in individual windows open simultaneously is one of Director's strengths. There are many different types of window (windowType) for cross and platform specific uses, with and without menu bars etc.

For more on MIAWS click here.

Strings

Text characters in Field text members are called strings.The example script below populates a field text member entitled "counter" with text (a string) which displays the time elapsed for a QuickTime video cast member placed in channel (sprite) 1 of Directors score.

Movietime is the current position or time (elapsed) of the video clip in ticks (60 per second). In the equation, movietime is divided by 60 to produce a result in seconds.

member("counter").text = string (sprite(1).movietime / 60 & " seconds elapsed")

download icon Calculator tutorial movie (.dir)

Need help downloading this file?