[EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
> I am producing a movie that will be distributed globally.
> I was wondering how well the clock behavoir functions on various systems. If
> it works by reading  the windows clock settings, does this falter when used on
> non english language versions of Windows.

Hi Tim,

The "Analog Clock" behavior was written in Director 6, before the systemDate
function was introduced.  The systemDate function includes an undocumented
.seconds property.  This is not entirely reliable, which may be why it is
not documented.  You can use (the systemDate).seconds to return the number
of seconds since midnight.


Try this in a Movie Script:

on getTimeRegardlessOfLanguageVersion()
  ms = the milliseconds
  tSeconds = (the systemDate).seconds
  tMinutes = tSeconds / 60
  tHours   = tMinutes / 60
  
  tMinutes = tMinutes mod 60
  if tMinutes < 10 then
    tMinutes = "0"&tMinutes
  end if
  
  tSeconds = tSeconds mod 60
  if tSeconds < 10 then
    tSeconds = "0"&tSeconds
  end if
  
  put the milliseconds - ms
  return tHours&":"&tMinutes&":"&tSeconds&& ms mod 1000
end



Now watch this expression in the Watcher window:

getTimeRegardlessOfLanguageVersion()


You may see that the seconds are not updated regularly.  On my Mac, I see
two-second jumps on an irregular basis.  The output in the Message window
shows that the handler does not take any significant time to execute, and
the changing value of the milliseconds in the Watcher window shows that the
handler is executed many times a second.  The irregularity may be due to
Director hogging as many cpu ticks as it can, but I have no direct evidence
of this.

The revised Analog Clock behavior below uses (the systemDate).seconds for
the minute and hour hands.  To ensure the second-hand moves at a steady
pace, I count the ticks or the milliseconds since the last full minute
before the clock started.  If the clock starts at a moment when (the
systemDate).seconds is out by a second or so, the clock will always be out
by that amount.  This seems (to me) to be a reasonable compromise between
accuracy and complexity.

In my tests, the clock appears to be more accurate on Macintosh when I count
the ticks, and on Windows when I count the milliseconds.  Presumably this is
because 1000 does not divide neatly by 60, and so there are rounding errors
if the non-native timing system is used.

Cheers,

James


----------------------------------------------------------------------------


-- ANALOG CLOCK --
--
-- 13 September 1998 written for the D7 Behaviors Palette by
--                   James Newton
--  7 January 2000   K. Miller: Added isOKToAttach handler and
--                   removed resulting redundant error checking code
-- 20 November 2001  JN: modified to use (the systemDate).seconds, the
--                   ticks on a Mac and the milliseconds on Windows




-- PROPERTIES --

property mySprite
-- author-defined parameters
property myClockHand    -- second/minute/hour hand

-- internal properties
property myUnitAngle  -- angular movement for each second since
property myTime       -- number of seconds since midnight/launch
property myStartTime  -- number of ticks/milliseconds when clock
--                       started (only used by second hand)
property isOnMac      -- TRUE if the movie is running on a Mac



-- EVENT HANDLERS --

on beginSprite(me)
  me.mInitialize()
end beginSprite



on exitFrame(me)
  me.mUpdate()
end exitFrame




-- PRIVATE METHODS --

on mInitialize(me) ---------------------------------------------------
  -- Sent by beginSprite()
  --------------------------------------------------------------------
  
  mySprite = sprite(me.spriteNum)
  myTime   = the systemDate.seconds
  isOnMac    = the platform contains "Mac"
  
  -- Determine how fast this hand turns
  case myClockHand of
    "Second hand":
      tSecondsPerTurn = 60
      -- Use the ticks or the milliseconds to update the second hand
      myTime   = myTime mod 60 -- seconds into this minute
      if isOnMac then
        tSeconds = the ticks / 60 -- seconds since launch
        myStartTime = (tSeconds - myTime) * 60
      else
        tSeconds = the milliseconds / 1000 -- seconds since launch
        myStartTime = (tSeconds - myTime) * 1000
      end if
      
    "Minute hand":
      tSecondsPerTurn = 60 * 60
      
    "Hour hand":
      tSecondsPerTurn = 12 * 60 * 60
  end case
  
  myUnitAngle    = 360.0 / tSecondsPerTurn
end Initialize 



on mUpdate(me)  ------------------------------------------------------
  -- Sent by exitFrame
  --
  -- ACTION: Updates the minute and hour hands according to
  -- (the systemDate).seconds.  Because of the irregularity of this
  -- undocumented property, the second hand is updated using a
  -- the milliseconds instead.
  --------------------------------------------------------------------
  
  if myClockHand = "Second hand" then
    if isOnMac then
      tSeconds = (the ticks- myStartTime)  / 60
    else
      tSeconds = (the milliseconds - myStartTime) / 1000
    end if
    
  else -- Minute and hour hands can absorb a few seconds either way
    tSeconds = the systemDate.seconds
  end if
  
  if myTime <> tSeconds then
    -- Director has received an update on the time
    myTime = tSeconds
  else
    exit
  end if
  
  mySprite.rotation = tSeconds * myUnitAngle
end mUpdate




-- BEHAVIOR PARAMETERS AND DESCRIPTION --

on isOKToAttach(me, aSpriteType, aSpriteNumber)
  -- Accept only Flash and VectorShape members
  if aSpriteType = #graphic then
    case sprite(aSpriteNumber).member.type of
      #flash, #vectorShape: return TRUE
    end case
  end if
  
  return FALSE
end isOKToAttach 



on getPropertyDescriptionList(me)
  tPropertiesList = [:]
  
  tPropertiesList[ \
#myClockHand ] = [ \
 #comment: "Sprite behaves as", \
 #format:  #string, \
 #default: "Second hand", \
 #range: ["Second hand", "Minute hand", "Hour hand"] \
]
  
  return tPropertiesList
end getPropertyDescriptionList



on getBehaviorTooltip(me)
  return \
"Use with Flash or vector shape members."&RETURN&RETURN&\
"Creates second-, minute- and hour-hands for a clock."&RETURN&RETURN&\
"Use a different sprite for each hand, and align the"&RETURN&\
"registration points.  Hands synchronise automatically"&RETURN&\
"with the computer's internal clock."
end getBehaviorTooltip



on getBehaviorDescription(me)
  return \
"ANALOG CLOCK"&RETURN&RETURN&\
"This behavior turns a Flash or vector shape member into a clock hand.  The
artwork should be created in the '12 o'clock' position.  The hand is
automatically rotated to indicate the current time according to the
computer's internal clock."&RETURN&RETURN&\
"Use three sprites to create a clock with second-, minute- and hour-hands
and drop this behavior onto each hand in turn.  Each hand will rotate around
its registration point; for the best effect, align the registration points
of the separate hands."&RETURN&RETURN&\
"PARAMETERS:"&RETURN&\
"* Clock hand: allows a choice between second hand, minute hand and hour
hand"
end getBehaviorDescription


[To remove yourself from this list, or to change to digest mode, go to
http://www.penworks.com/LUJ/lingo-l.cgi  To post messages to the list,
email [EMAIL PROTECTED]  (Problems, email [EMAIL PROTECTED])
Lingo-L is for learning and helping with programming Lingo.  Thanks!]

Reply via email to