Articles Archive
Articles Search
Director Wiki
 

Using Score Labels to Create Navigation Buttons

August 23, 2000
by Gary Rosenzweig

It bothers me that some Director programmers do not use Score labels in their movies. Just as a programmer should use useful, clear variable and handler names, one should also label all of the important frames in the Score. You can actually use these labels for more than just commentary. You can read their values with the labelList system property, and match those values with the frame numbers using the frame function. Here is a handler that does just that:

on getLabels

  gLabels = [:]

  repeat with i = 1 to (the labelList).line.count-1
    addProp gLabels, label((the labelList).line[i]), (the labelList).line[i]
  end repeat

end

The result is a property list that could look something like this:

[2: "Main Menu", 5: "Chapter 1", 7: "Chapter 2", 9: 
"Chapter 3", 11: "Chapter 4"]

This type of list could have many uses, depending on what your movie does. For instance, if you want to make a quick presentation movie, you could label each screen. Using go next and go previous, you can easily make buttons that allow the user to jump from labeled frame to labeled frame.

Even better, you could make these buttons show the names of the frames. All that you would need to do is to check the number of the current frame, use findPos to see which item in the property list matches the current frame, and then display the names of the next and previous frames.

Here is an on beginSprite handler, meant for a frame script, that does this. It will also check to see if the frame is the first or last, and display blanks for the next and previous label Text members if needed.

on beginSprite me

  f = findPos(gLabels,the frame)

  if f = 1 then
    member("Previous Label").text = ""
  else
    member("Previous Label").text = gLabels[f-1]
  end if

  if f = gLabels.count then
    member("Next Label").text = ""
  else
    member("Next Label").text = gLabels[f+1]
  end if

end

In this example movie, the Text members are shown on every frame, and double as buttons. Click on them to go to the frame that is shown.

Director 8 sample movies are available for download in Mac or PC format.

The great thing about this movie is that the Lingo code does not contain the names of the frames anywhere. These are all read at the beginning of the movie, from on prepareMovie. So, you could change the labels very easily, and let Lingo do the rest. You could also drop these scripts onto a massive presentation and instantly create previous and next navigation buttons.

Gary Rosenzweig's new book "Special Edition Using Director 8" is now available. It's the most comprehensive guide to Director ever, including tons of examples and demo movies. It's suitable for novices and experts alike. More information about the book can be found at http://clevermedia.com/resources/bookstore/book5.html. It can be purchased there, or in your local bookstore.

Gary Rosenzweig is the Chief Engineer, founder, and owner of CleverMedia, a game and multimedia development company in Denver, Colorado. He is the author of ten books on Macromedia Director and Flash, including his latest, Special Edition Using Director MX.

Copyright 1997-2017, Director Online. Article content copyright by respective authors.