2 Replies Latest reply on Jul 9, 2006 8:59 PM by BruceMasai

    Popup Menu Mystery!

    BruceMasai
      This popup menu example I got from the Director showme files fails to instruct where/how to direct the selected highlighted line where to go and didn't have an example of a functioning script that tells how a selected line branches off to another frame or movie. Please help me be able to make this a functioning capability of Director:

      -- Popup Menu behavior
      -----------------------------------------------------------
      -- This behavior uses a fixed size, field cast member to create a popup menu. The field displays one line of text when closed
      -- and opens when clicked to display all of its lines of text. Another sprite can open this popup menu by calling this behavior's
      -- openPopup handler. You attach this behavior to a field sprite. The behavior also requires a second field sprite above all other
      -- sprites on the Stage. The second field a Display Sprite behavior to identify itself.
      -- David Benman 2/98
      -----------------------------------------------------------
      -- popupSprite - The number of the sprite containing the menu
      -- popupMember - The name of the field member containing the menu
      -- textHeight - The height in pixels of a line of text in the menu
      -- closedLocV - The menu's location when it is closed
      -- popupOpen - True/False indicator of when the menu has been selected and opened.
      -- selectedLine - The number of the menuu line that the cursor is over.
      -- closedRect - The rectangle of the closed menu.
      -- openRect - The rectangle of the open menu.
      -- cursorOver - True/False indicator of when the cursor is over the menu

      property popupSprite, popupMember, textHeight, closedLocV, popupOpen, selectedLine, closedRect, openRect, cursorOver, displaySprite, previousLine

      -- This handler establishes the size for the open and closed menu. The handler also prepares the menu
      -- for when it first displays. on beginSprite me

      set popupSprite to the spriteNum of me
      set popupMember to the member of sprite popupSprite
      set textHeight to the lineHeight of member popupMember
      set closedLocV to the locV of sprite popupSprite

      -- Creates rects representing the size of the menu when it is open and closed.
      set openRect to duplicate(the rect of member popupMember)
      set closedRect to duplicate(openRect)
      set the bottom of closedRect to textHeight + (0.2 * textHeight)

      -- Closes the menu to a single line to start
      set the rect of member popupMember to closedRect

      -- Makes the first line of the menu selected by default
      set selectedLine to 1
      set previousLine to selectedLine

      -- Scrolls the menu so that the first line displays
      set the scrollTop of popupMember to selectedLine * textHeight - textHeight

      -- Provides a default value for the display sprite in case you don't use one
      set displaySprite to 0
      end


      -- This handler opens the menu when you click.
      on mouseDown me
      openPopup me
      end

      -- This handler closes the menu when you release the mouse button if the menu is the one selected in the mouseDown script.
      on mouseUp me
      if popupOpen then
      closePopup me
      end if
      end

      -- This handler closes the menu when you release the mouse button and the cursor is outside the menu.
      -- Also, the menu has to be the one selected in the mouseDown script.
      on mouseUpOutside me
      if popupOpen then
      closePopup me
      end if
      end


      -- These handlers determine when the cursor is over the menu
      on mouseLeave me
      set cursorOver to FALSE
      end

      on mouseEnter me
      set cursorOver to TRUE
      end


      -- This handler opens the menu expanding it upwards, downwards, or in both direcctions so that the menu's
      -- current line remains at the same screen position. The handler also causes the display sprite to mimic the
      -- menu's actions.
      on openPopup me, startLine

      -- Sets selectedLine to a specific value when a calling handler provides startLine as a parameter. Otherwise,
      -- selectedLine is the number of the previously selected
      line for this menu.
      if NOT voidP(startLine) then
      set selectedLine to startLine
      end if

      -- Moves the menu offstage to hide the following manipulations to its cast member
      set the locV of sprite popupSprite to -100
      updateStage

      -- Scrolls the menu text to the top and opens the menu.
      set the scrollTop of popupMember to 0
      set the rect of member popUpMember to openRect


      -- Calculates the menu's open location so that its current line stays in the same location on the screen
      set openLocation to closedLocV - ((selectedLine * textHeight) - textHeight)

      -- Moves the menu to its open location
      set the locV of sprite popupSprite to openLocation

      -- Places a copy of the menu over the active menu and all other sprites
      set the loc of sprite displaySprite to the loc of sprite popupSprite
      set the locV of sprite displaySprite to openLocation
      set the member of sprite displaySprite to popUpMember

      updateStage

      -- Highlights the menu line the cursor is over
      hilite line selectedLine of member popupMember

      set popupOpen to TRUE
      end

      -- This handler closes the popup
      on closePopup me

      -- Hides both the menu and the copy
      set the locV of sprite displaySprite to -100
      set the locV of sprite popupSprite to -100
      updateStage

      -- Closes and scrolls the menu so that only the current line shows
      set the rect of member popUpMember to closedRect
      set the scrollTop of popupMember to selectedLine * textHeight - textHeight

      -- Places the menu in its closed location
      set the locV of sprite popupSprite to closedLocV

      -- Tells all the other sprites the number of the selected menu line.
      sendAllSprites(#popupSelection, popupMember, selectedLine)

      -- Erases the menu highlight
      if selectedLine = 1 then
      hilite line 2 of member popupMember
      else
      hilite line 1 of member popupMember
      end if

      set popupOpen to FALSE
      end


      -- This handler updates the highlight when the menu is open
      -- and the cursor is over it.
      on prepareframe me

      if popupOpen and cursorOver then

      -- Makes the the selected line the line the cursor is over.
      if the mouseH <> the locH of sprite popupSprite then
      set selectedLine to the mouseLine
      end if

      -- Keeps the the selected line the line when the cursor moved off the menu.
      if selectedLine < 1 and previousLine > 0 then
      set selectedLine to previousLine
      end if


      -- Highlight a line if it is different from the line selected in the previous frame
      if selectedLine <> previousLine then
      hilite line selectedLine of member popupMember
      set previousLine to selectedLine
      end if
      end if
      end

      -- This handler determines the sprite number for the display sprite in response to a message sent by the display sprite.
      on initDisplaySprite me, spriteNumber
      set displaySprite to spriteNumber
      end