Articles Archive
Articles Search
Director Wiki
 

DIY Slide Shows

March 30, 1998
by Pat McClellan

Dear Multimedia Handyman,

Is there a way to create a projector that can just be dropped into a whole pile of images, or at the root of a director tree and automatically go thru the images directories (.JPGs are fine) and display them, like in a slideshow format. So that the images can change, but the function remains the same and does not need to be "customized" for the image names?

Rick Gaylor

Dear Rick,

There are two key lingo terms you'll need to use to make this little utility: getNthFileNameInFolder and the fileName of member. Take a quick look at both terms in your Lingo Dictionary.

Our strategy will be to build a projector that has a dummy castmember which we'll re-link to all of the suitable files in our external directory. The first step is to build a list of the suitable files. For this, use getNthFileNameInFolder. As you specify in your question, we'll assume that all of the files we want to look at are in the same directory as our movie.


on buildList
  global gFileList
  set gFileList = []
  repeat with i = 1 to the maxInteger
    set thisFile = getNthFileNameInFolder¬
      (the pathName, i) 
    if thisFile = EMPTY then exit repeat
    append(gFileList, thisFile)
  end repeat
end buildList

This handler is pretty much what they specify in the Lingo Dictionary, but let's add a few things. For starters, this handler will include the name of the projector or dir file in the list. Obviously, you don't want to link your cast member to the Director movie. Let's add a filter to the handler, which will go into the handler just above the "append..." line.

if thisFile = the movie then next repeat

Since we only want to display graphic images, if you're using Windows naming conventions (using the file extension in the file name), then you can do some additional filtering to prevent errors at runtime. For example, this version of the handler assures that the fileName has a standard graphic extension before adding it to the list.

on buildList
  global gFileList
    set gFileList = []
    repeat with i = 1 to the maxInteger
      set thisFile = getNthFileNameInFolder¬
        (the pathName, i) 
      if thisFile = EMPTY then exit repeat
      if thisFile = the movie then next repeat
      set fileTypes = [".bmp", ".pct", ".jpg", ".gif"]
      set howManyTypes = count(fileTypes)
      repeat with thisType = 1 to howManyTypes
        set extension = getAt(fileTypes, thisType)
        if thisFile contains extension then
          append(gFileList, thisFile)
        end if
      end repeat    
        end repeat
end buildList

Now that we know how to build the file list, we'll need some handlers to apply to Next and Back buttons. Let's create a global variable called gFileIndex which will keep track of which file is currently being linked and displayed. Then, all we need to do is increment or decrement this gFileIndex value whenever the Next or Back buttons (respectively) are pressed. I also put in a bit of code so that the file list will loop.

on mouseUp
  -- attach to Next button
  global gFileList, gFileIndex
  set gFileIndex = gFileIndex + 1
  if gFileIndex > count(gFileList) then
    set gFileIndex = 1
  end if
  set whichFile = getAt (gFileList, gFileIndex)
  set the fileName of member "display" ¬
    to whichFile
  set the picture of member "display" = set ¬
    the picture of member "display"
  updateStage
end
on mouseUp
  -- attach to Back button
  global gFileList, gFileIndex
  set gFileIndex = gFileIndex - 1
  if gFileIndex = 0  then
    set gFileIndex = count(gFileList)
  end if
  set whichFile = getAt (gFileList, gFileIndex)
  set the fileName of member "display" ¬
    to whichFile
  set the picture of member "display" = set ¬
    the picture of member "display"
  updateStage
end

Note that I included a line before the updateStage command which refers to "the picture of member 'display'". This forces the registration point for the new graphic to center itself. Otherwise, the graphic changes but the registration point becomes the top left corner of each graphic.

To wrap things up, you'll need to initiate the gFileIndex = 1 in the startMovie, and also call the buildList handler.


on startMovie
  global gFileIndex
  set gFileIndex = 1
  buildList
end

That wraps up the Lingo. In your cast, create a graphic member called "display". Just put a single dot in the cast member. Drag it to the score so that it is centered on your stage (and make sure your stage is large enough to display any graphics you may want to view.) Put the Next and Back buttons on the stage, and set up the movie to loop. Create your projector & you're finished.

If you want to get fancy, you could create another movie which launches this viewer as a movie in a window (MIAW). The advantage to that MIAWs can be resized, which might be a nice feature for a viewer. If you do that, you'll want to set the stage location for the first movie at coordinates like (1600, 1)... something that won't appear on the screen. Then, have that movie automatically open the MIAW on screen.

One last note, you'll need to include the appropriate Xtras in your projector (such as the Gif Import Xtra and the JPEG Import Xtra). You can included them by selecting "Include Xtras" in the Options menu when you make the projector. Good luck with your project.

You can download the code for this article in either HQX or ZIP format.

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-2024, Director Online. Article content copyright by respective authors.