Contents
Articles
Behaviors
Books
Director News
Director Web Sites
FAQ
Games
Mailing Lists
News Groups
Project Examples
Reviews
Software
Tools
Useful Web Sites
Utilities
Xtras

Don't miss these
Wait for explode to finish
Image Xport
Grabber
Enhancer Xtra
Killing Moon / Director
display TreeView
Font Pool
Macromedia
asASIOout
Get Visual Line Count and Current Visual Line of Insertion
 

 

 

Behavior PopUp Menu

Added on 6/10/1999

 

Compatibilities:
behavior D6_5 Mac PC

This item has not yet been rated

Author: RettCrocker

This behavior turns any text field into a popup menu.

--There are four options...
--1. The item list: A list of the lines in the popup menu.
--2. Function to call: This is the function called when an item in the popup menu is selected.  The number of the
line selected is passed to the function specified.
--3. The direction: This specifies the direction the menu will pop.  Auto pops in the direction most appropriate to the position of the currently selected item in the list.
--4. The number of flashes: This specifies the number of flashes you will see when an item is selected.  In the MacOS the default is 3 so that is the default here as well.
---------------------------
--Code by Rett Crocker 1997
--If you use this code I would appreciate a mention in the
--credits.  Enjoy.
---------------------------
property pItemList, pEventToCall, pDirection, pSelectFlash
property pSprite, pField, pSwitchField, pLocV, pCurrent
property pFullField, pLastML, pDown

on beginSprite me
  set pSprite = the spriteNum of me
  set pField = the memberNum of sprite pSprite
  set pLocV = the locV of sprite pSprite
  set pFullField = ""
  set lDelim = the itemDelimiter
  set the itemDelimiter = ","
  set lText = pItemList
  set pItemList = []
  set lNoItems = the number of items of lText
  repeat with x = 1 to lNoItems
    set lCurrItem = (item x of lText)
    setAt(pItemList, x, lCurrItem)
    put lCurrItem & RETURN after pFullField
  end repeat
  delete line (the number of lines of pFullField) of pFullField
  set pCurrent = line 1 of pFullField
  put pCurrent into field pField
  set pDown = 0
end

on mouseDown me
  set pLastML = 0
  set pDown = 1
  set pSwitchField = findEmpty(member 1)
  duplicate member pField, pSwitchField
  put pFullField into field pSwitchField
  case pDirection of
    #auto:
      set lLine = getPos(pItemList, pCurrent)
      set lLineHeight = the lineHeight of member pField
      set lV = (the locV of sprite pSprite) - ((lLine - 1) * lLineHeight)
      set the locV of sprite pSprite = lV
      set the memberNum of sprite pSprite = pSwitchField
    #up:
      set lNoLines = the number of lines of pFullField
      set lLineHeight = the lineHeight of member pField
      set lDiff = (lNoLines - 1) * lLineHeight
      set lV = (the locV of sprite pSprite) - lDiff
      set the locV of sprite pSprite = lV
      set the memberNum of sprite pSprite = pSwitchField
    otherwise
      set the memberNum of sprite pSprite = pSwitchField
  end case
  updatestage
end

on mouseWithin me
  if pDown = 1 then
    set lML = the mouseLine
    if lML > 0 then
      if lML <> pLastML then
        hilite line lML of field pSwitchField
        set pLastML = lML
      end if
    end if
  end if
end

on mouseUp me
  if pLastML > 0 then
    set pCurrent = line pLastML of field pSwitchField
    if pSelectFlash > 0 then
      set lUnHiliteLine = ((the number of lines of field pSwitchField) + 1)
      hilite line lUnHiliteLine of field pSwitchField
      updatestage
      repeat with x = 1 to pSelectFlash
        hilite line pLastML of field pSwitchField
        updatestage
        hilite line lUnHiliteLine of field pSwitchField
        updatestage
      end repeat
    end if
    set lString = pEventToCall & SPACE & pLastML
    do lString
  end if
  set pDown = 0
  put pCurrent into field pField
  set the locV of sprite pSprite = pLocV
  set the memberNum of sprite pSprite = pField
  updatestage
  erase member pSwitchField
end

on mouseUpOutside me
  set pDown = 0
  put pCurrent into field pField
  set the locV of sprite pSprite = pLocV
  set the memberNum of sprite pSprite = pField
  updatestage
  erase member pSwitchField
end

on getPropertyDescriptionList me
  set description = [:]
  addProp description,#pItemList,[#default:"",#format:#string,#comment:"Items in menu (put a comma between each item):"]
  addProp description,#pEventToCall,[#default:"",#format:#string,#comment:"Function to call:"]
  addProp description,#pDirection,[#default:#auto,#format:#symbol,#comment:"Pop direction:", #range:[#auto, #down, #up]]
  addProp description,#pSelectFlash,[#default:3,#format:#integer,#comment:"Number of flashes on select:"]
  return description
end

on getBehaviorDescription
  set lLine01 = " Pop Behavior:" & RETURN
  set lLine02 = " This behavior turns any text field into a popup menu." & RETURN
  set lLine03 = " There are four options..." & RETURN
  set lLine04 = " 1. The item list: A list of the lines in the popup menu." & RETURN
  set lLine05 = " 2. Function to call: This is the function called when an" & RETURN
  set lLine06 = " item in the popup menu is selected.  The number of the" & RETURN
  set lLine07 = " line selected is passed to the function specified." & RETURN
  set lLine08 = " 3. The direction: This specifies the direction the menu" & RETURN
  set lLine09 = " will pop.  Auto pops in the direction most appropriate" & RETURN
  set lLine10 = " to the position of the currently selected item in the list." & RETURN
  set lLine11 = " 4. The number of flashes: This specifies the number of" & RETURN
  set lLine12 = " flashes you will see when an item is selected.  In the" & RETURN
  set lLine13 = " MacOS the default is 3 so that is the default here as well." & RETURN
  set lLine14 = "----------------------------" & RETURN
  set lLine15 = " Code by Rett Crocker 1997" & RETURN
  set lLine16 = " If you use this code I would appreciate a mention in the" & RETURN
  set lLine17 = " credits.  Enjoy." & RETURN
  set lLine18 = "----------------------------" & RETURN
  return lLine01 & lLine02 & lLine03 & lLine04 & lLine05 & lLine06 & lLine07 & lLine08 & lLine09 & lLine10 & lLine11 & lLine12 & lLine13 & lLine14 & lLine15 & lLine16 & lLine17 & lLine18
end  

 


Contact

MMI
36 South Court Sq
Suite 300
Newnan, GA 30263
USA

Send e-mail