-- FIELD EVENTS -- -- -- © June 2003 - September 2005, OpenSpark Interactive Ltd -- -- ---------------------------------------------------------------------- -- This parent script can be used to generate #openField and -- #closeField events when the user shifts the keyboard focus from -- one sprite to another. The events are sent first to the sprite -- in question, but may be handled at a Movie level if no behavior on -- the sprite contains the appropriate handler. Movie handlers should -- have a dummy first parameter, and a second parameter to retrieve -- the spriteNum of the sprite affected: -- -- on openField(dummy, aSpriteNumber) -- -- instructions -- end -- -- If sprite(aSpriteNumber) has a behavior, but not an openField or -- closeField handler, dummy will take the value . If the -- sprite has no behaviors, dummy will take the value #openField or -- #closeField. -- -- This parent script needs to be initialized by a call to its Start() -- handler. This alters the mouseDownScript and the keyDownScript. -- Other scripts should take care not to remove these alterations, -- otherwise the feature will stop working. -- -- script("Field Events").start() -- -- As the user types, the script watches for changes in sprite focus. -- These can be of three types: -- * focus moves to an editable sprite from a non-editable sprite -- * focus moves from an editable sprite to a non-editable sprite -- * focus moves to one editable sprite to another editable sprite -- -- All three of these changes can be effected by a mouse click which -- may make the playback head jump to a different frame. The -- last can also be effected by a keyPress (autoTab), while remaining -- at the current marker. -- -- NOTE: Field members created with Director 7.0 will react to the TAB -- key as if autoTab were set to TRUE, even if this is not the case. -- This behavior persists, even when the movie is updated. If -- unexpected auto-tabbing occurs in later versions of Director, you -- should create a new field to replace the D7 one. -- ---------------------------------------------------------------------- -- WATCHER EXPRESSIONS -- ------------------- -- script("Field Events").focusSprite -- the mouseDownScript -- the keyDownScript ---------------------------------------------------------------------- -- SCRIPT PROPERTIES -- property focusSprite -- spriteNum of the most recent field or text -- sprite to be edited (may not be the -- keyboardFocusSprite since this may be an -- OSControl sprite). --- PUBLIC SCRIPT METHODS -- on Start(me) --------------------------------------------------------- -- ACTION: Add calls to handlers in this script to the -- mouseDownScript and the keyDownScript. Any existing -- content for these primary handlers is maintained. -------------------------------------------------------------------- tInstructions = the mouseDownScript tCommand = me&".WatchMouseDown()" if not (tInstructions contains tCommand) then put RETURN&tCommand after tInstructions the mouseDownScript = tInstructions end if tInstructions = the keyDownScript tCommand = me&".WatchKeyDown()" if not (tInstructions contains tCommand) then put RETURN&tCommand after tInstructions the keyDownScript = tInstructions end if end Start on WatchMouseDown(me) ------------------------------------------------ -- RECEIVED from the mouseDownScript -- ACTION: Detects changes in sprite focus due to a mouse click. -- The mouse click can be on an editable sprite or a non- -- editable sprite. It need not occur in the frame where -- where the current keyboardFocusSprite appears. -------------------------------------------------------------------- tSpriteNum = the clickOn if not tSpriteNum then -- click on the background -- The keyboardFocus sprite will not be affected exit else if tSpriteNum = focusSprite then -- There is no change of focus exit end if -- If we get here, then the user has clicked on a sprite other than -- the current focusSprite. me.mChangeFocus(tSpriteNum) end WatchMouseDown on WatchKeyDown(me) -------------------------------------------------- -- RECEIVED from the mouseDownScript -- ACTION: Detects changes in sprite focus due to a mouse click. -- The mouse click can be on an editable sprite or a non- -- editable sprite. It need not occur in the frame where -- where the current keyboardFocusSprite appears. -- Generates a #closeField and/or an #openField event. -------------------------------------------------------------------- tFocusSprite = the keyBoardFocusSprite if tFocusSprite = focusSprite then if the key = TAB then -- The user may be tabbing to the next editable sprite tMember = sprite(tFocusSprite).member global version if char 1 to 2 of version = "7." then -- Field members created with Director 7.0 will react to -- the TAB key as if autoTab were set to TRUE, even if this -- is not the case. tAutoTab = (tMember.type = #field) or tMember.autoTab else if the movieFileVersion = "700" then -- We have to hope that no editable field members have been -- created on the fly using a later version of Director. tAutoTab = (tMember.type = #field) or tMember.autoTab else -- Field members created in later versions behave correctly tAutoTab = tMember.autoTab end if if tAutoTab then me.mOpenNextEditableSprite() end if end if else me.mChangeFocus(tFocusSprite) end if end WatchKeyDown -- PRIVATE METHODS -- on mChangeFocus(me, aFocusSprite) ------------------------------------ -- SENT BY WatchMouseDown(), WatchKeyDown() -- ACTION: Checks if the keyboard focus is changing, and if so, --- sends the appropriate events -------------------------------------------------------------------- if not me.mSpriteIsEditable(aFocusSprite) then -- Keyboard focus will remain with the current editable sprite exit end if if focusSprite then -- An editable sprite currently has focus: it's about to lose it sendSprite(focusSprite, #closeField, focusSprite) end if focusSprite = aFocusSprite sendSprite(focusSprite, #openField, focusSprite) end mChangeFocus on mOpenNextEditableSprite(me) --------------------------------------- -- SENT BY WatchKeyDown() if the user presses TAB in an autoTab -- sprite (except for fields in Director 7). -- ACTION: Looks for the next editable sprite, and if there is one -- prematurely declares that the focus has moved to it. If -- no other sprites are editable, then the focus doesn't -- change. -------------------------------------------------------------------- tCount = the lastChannel repeat with i = focusSprite + 1 to tCount if me.mSpriteIsEditable(i) then -- We've found the future keyboardFocusSprite. Close the -- current sprite and open the new one... sendSprite(focusSprite, #closeField, focusSprite) focusSprite = i sendSprite(focusSprite, #openField, focusSprite) -- ... and stop searching exit end if end repeat -- If we get here, we've haven't found an editable sprite in any of -- the higher-numbered channels. Start over from 1. tCount = focusSprite - 1 repeat with i = 1 to tCount if me.mSpriteIsEditable(i) then -- We've found the future keyboardFocusSprite. Close the -- current sprite and open the new one... sendSprite(focusSprite, #closeField, focusSprite) focusSprite = i sendSprite(focusSprite, #openField, focusSprite) -- ... and stop searching exit end if end repeat end mOpenNextEditableSprite on mSpriteIsEditable(me, aSpriteNumber) ------------------------------ -- -------------------------------------------------------------------- tSprite = sprite(aSpriteNumber) tMember = tSprite.member case tMember.type of #field, #text: if tMember.editable or tSprite.editable then return aSpriteNumber end if end case return 0 end mSpriteIsEditable