-- 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 -- 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 property myMilliseconds -- number of milliseconds when clock started -- (only used by second hand) -- 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 -- Determine how fast this hand turns case myClockHand of "Second hand": tSecondsPerTurn = 60 -- Use the milliseconds to update the second hand myTime = myTime mod 60 -- seconds into this minute tSeconds = the milliseconds / 1000 -- seconds since launch myMilliseconds = (tSeconds - myTime) * 1000 "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 tSeconds = (the milliseconds - myMilliseconds) / 1000 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