Get the name of a label that's before a given frame number

Date: Sun Jul 18 16:15:56 MST 1999
From: Jeremy Seitz <jeremy@studiovr.com>
Subject: Get the name of a label that's before a given frame number
Often when you are programming a project that uses a lot of markers, it is sometimes a pain to determine where a particular frame falls. I use markers to identify where sections start (so they are easy to jump to), so this function comes in handy a lot.

So here's a Director 7 behavior that will translate a frame number into the frame label that exists on or before that number. Just pop this function into any movie script and you can get going.

on getlabel f
  -- returns the name of the label found before the 
  -- current frame
  -- (returns 0 if there is no label before the 
  -- requested frame)
  
  -- Jeremy Seitz
  -- StudioVR, Inc.
  -- www.studiovr.com
  -- 7/18/1999
  
  location=-1  
  i=1
  count = (the labellist).line.count
  repeat while i<=count and location=-1  
    if marker((the labellist).line[i])>(f) then
      if i=1 then 
        location=0
      else        
        location=(the labellist).line[i-1]
      end if      
    end if  
    i=i+1
  end repeat
  if location=-1 then location=(the labellist).line[count-1]
  return location  
end