on activateSlider
------------------------------------------------------------------
-- The Popper
-- © 1996, 1997 alan
-- http://www.mcli.dist.maricopa.edu/alan/
-- maricopa community colleges
--
-- This movie demonstrates how to create functional pop-up menus
-- using parent-child scripts.
--
-- It may be used but only if these credits are kept in tact
------------------------------------------------------------------
property spriteNum, popField, currLine, currText
-- popUp menu parent script
-- properties:
-- spriteNum = the text cast that contains the pop menu
-- popField = name of text cast for sprite spriteNum
-- currLine = line selected from menu
-- currtext = text of selected line
on new me, sNum
-- this used to be the "birth" handler ;-)
set spriteNum = sNum
set popField to the name of the member of sprite sNum
set currLine = -1
set currText = ""
return me
end
on popUp me, popSource
-- handles the button action and popup menu generated
-- by the sprite popSource
put the memberNum of member "button_up" into origButton
set the memberNum of sprite popSource = origButton + 1
-- animate the button by swapping with next cast
-- member and offsetting location
set the loc of sprite popSource = the loc of sprite popSource + point(3,3)
-- just for this demo, also animate the button labels
set the loc of sprite (popSource + 13) = the loc of sprite (popSource + 13) + point(3,3)
-- move the pop up menu adjance to the item that called it
set the loc of sprite spriteNum = point(the right of sprite popSource, ¬
the top of sprite popSource)
updateStage
-- loop while mouse is held
repeat while the mouseDown
-- get line number under the mouse
set lastLine = the mouseLine
-- check that the mouse is over the sprite for the menu
-- and also that it is not on the border of the text cast
if rollover (the spriteNum of me) and lastLine <> -1 then
-- update selection only if different from previous
-- loop (avoids flashing hilite)
if lastLine <> the currline of me then
set the currLine of me to lastLine
-- determine the starting character for the selection
-- by counting the characters in the preceding lines
-- NOTE: if you simply script
-- hilite line lastLine of ...
-- the effect will be to only hilite the words
-- of each line and not the entire width of the menu
-- text. That's why the extra gymnastics of
-- counting chars.
if lastLine = 1 then
set firstChar = 1
else
set firstChar = length ( line 1 to lastLine - 1 of ¬
field popField ) + 2
end if
-- hilite the selected line
hilite char firstChar to length (line 1 to lastLine ¬
of field popField ) + 1 ¬
of field popField
end if
else
-- mouse is down but outside of menu; hilite the last line
-- which is not visible
hilite line (the number of lines in field popField) of field popField
set currLine = -1
end if
end repeat
-- return line and text of selected menu item
if currLine = -1 then
set currText = ""
else
set currText = line currLine of field popField
end if
-- restore the button to undepressed state
set the memberNum of sprite popSource = origButton
set the loc of sprite popSource = the loc of sprite popSource + point(-3,-3)
set the loc of sprite (popSource + 13) = the loc of sprite (popSource + 13) ¬
+ point(-3,-3)
-- move popmenu sprite off stage
set the locH of sprite spriteNum to -1000
updateStage
end
|
| This creates an object for each instance of a pop up menu, so potentially you could spawn billions of them. It uses a field cast member to display the menu, and it has to do some tricky things to hilight the complete line of the selected text. When called from a mousedown script, you must create the menu object, and then check for its return status so you know what to do with the selection.
lingo era = v4-5 This was some of my first parent script writing, but still appears to work ok.
|