Articles Archive
Articles Search
Director Wiki
 

Renaming castMembers

June 8, 1998
by Pat McClellan

Dear Multimedia Handyman,

I'm working on a program which has hundreds of graphics which I need to name so that my Lingo behaviors can find them and swap them into the correct sprites. I'm trying to figure out a way to avoid manually typing in all the names. The images are displayed in a group of 8 per "page", with 114 pages in all. I want to use the following naming convention: pageX_imageX. Can you help?

Kevin Gutherie

Dear Kevin,

I'm glad you asked, because you can save a lot of time and -- more importantly -- avoid typing errors which would screw up your Lingo execution. What you need to do is create a utility handler. This is a handler which will only be used during authoring. For many people this seems to be a revolutionary idea, but why not put the power of Lingo to use while authoring? We'll create the handler in a movie script, then call it from the message window.

Let's start by setting up the cast. I'll assume that the castLib is called "images". The images need to be in sequence with no empty cast members in between. I'll assume that they are in order: page 1, image1 through image8; page 2, image1 through image 8; etc. When you're finished, you should have 912 cast members (114 pages * 8 images/page).

The handler will start by initializing our page and image numbers at 1. Then, we'll use a repeat loop to step through all the cast members in the castLib, with an if-then statement to watch our image number and increment the page and image numbers. We could hardcode in the name of the castLib and the numbers of the first and last cast members, but I prefer to leave those as parameters -- just a good habit for flexibility and reuse.


on nameImage whichCastLib, firstMemNum, lastMemNum
  set whichPage = 1
  set whichImage = 1
  repeat with whichCastNum = firstMemNum to lastMemNum
    put "page" & whichPage & "_image" & whichImage ¬
          into theName
    set the name of member whichCastNum of castLib ¬
          whichCastLib to theName
    if whichImage = 8 then
      set whichImage = 1
      set whichPage = whichPage + 1
    else
      set whichImage = whichImage + 1
    end if
  end repeat
end

After compiling the script (click the little lightning bolt button in the script window), enter the following in the message window:
nameImage "images", 1, 912
When you press return, watch in awe as this handler cycles through your cast naming the cast members. I've reused this handler many times on many projects, simply by changing the name parsing specs.

Try to think of other uses for utility handlers while you're authoring. Prime candidates are repetitive tasks which involve properties which Lingo can access: locH, locV, regPoint, name, etc. I have been frustrated by the fact that we can't use Lingo to affect the graphic attributes. I'd love to be able to specify a crop setting for a series of graphics!

I'd enjoy hearing about the utilities handlers that others of you have used. I'm sure they'll be useful or inspirational to many others who face similar challenges.

Patrick McClellan is Director Online's co-founder. Pat is Vice President, Managing Director for Jack Morton Worldwide, a global experiential marketing company. He is responsible for the San Francisco office, which helps major technology clients to develop marketing communications programs to reach enterprise and consumer audiences.

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