Search content:

 

Personal Menu
Username:
Password:
Save password

Become a member

Forgot Password?

 

Don't miss these
Toggle DirectToStage Property of a Flash Member
Clear Embedded Font
Generic behavior to create a Shortcut
Relative Links
Stub Projector
Fast Blur Algorithm
Keycode
Made with Macromedia and Shockwave Licensing Programs
Toggle Pause / Play Audio
Set ViewScale Property of a Flash Sprite
MediaMacros Xtras Mall
 

 

 

Behavior Menu bar emulator

Added on 8/21/1999

 

Compatibilities:
behavior D7 D8 Mac PC Shockwave

This item has not yet been rated

Author: DannyKodicek

Add to a field sprite to emulate the standard lingo menu functions. Useful for SW or for creating menus with your own font styles

-- add to a field sprite to emulate the menu function in SW
-- Shortcuts work with shift rather than ctrl (an unfortunate necessity)
-- NB - this behaviour uses the mousedownscript and keydownscript,
-- and needs to be adapted if these are needed elsewhere in the movie

-- Danny Kodicek 1999 (please credit)
--Any comments / problems / improvements to danny@toifund.com

property pmenu -- the menu member
property pmouseselection -- the currently selected line
property pmenuitems -- list of lists of menu items for each menu
property popening -- is there a menu currently popped
property pmenudownsprite -- the sprite holding the menu popup (needs to contain a dot)
property pmenumember -- the member of the popup (created dynamically)
property ptoptext -- the menu bar text
property pfont, psize -- style of the text

on getpropertydescriptionlist me
  lyst=[:]
  addprop lyst, #pmenu, [#comment: "Member of menu text", #format: #field, #default:""]
  addprop lyst, #pmenudownsprite, [#comment: "Menu down sprite", #format: #integer, #default: 100]
  addprop lyst, #pfont, [#comment: "Font", #format: #string, #default: "Times"]
  addprop lyst, #psize, [#comment: "Font size", #format: #integer, #default: 12, #range: [#min: 8, #max: 18]]
  
  return lyst
end

on getbehaviordescription me
  t="Emulates the installmenu command; choose your own fonts"
  put "and sizes or use it in Shockwave" after t
  return t
end

on getbehaviortooltip me
  t="Add to a field sprite, specifying a second sprite for the"&return
  put "drop-down menu and a field cast member containing a standard"&return after t
  put "lingo menu (only supports enable, disable, lingo handler,"&return after t
  put "shortcut and blank line functions. Shortcuts use the shift key)"&return&return after t
  put"This will then emulate a standard menu bar with your specified"&return after t
  put "font style."&return&return after t
  put "Uses the mousedownscript and keydownscript." after t
  return t
end

on beginsprite me
  sprite(me.spritenum).member.font=pfont
  sprite(me.spritenum).member.fontsize=psize
  id=the itemdelimiter
  menutext=pmenu.text
  pmenuitems=[]
  currmenu=[]
  ptoptext=""
  repeat with i= 1 to the number of lines of menutext
    menuline=menutext.line[i]
    the itemdelimiter=":"
    if menuline.item[1]="menu" then
      if currmenu<>[] then
        add pmenuitems, currmenu
      end if
      currmenu=[]
      put menuline.item[2]&"      " after ptoptext
    else
      curritem=[#enabled:true]
      the itemdelimiter="|"
      menufunc=menuline.item[1]
      m=""
      addprop curritem, #shortcut, ""
      repeat with j=1 to the number of chars of menufunc
        if menufunc.char[j]="(" then
          setprop curritem, #enabled, false
          if j            if menufunc.char[j+1]="-" then
              m=" "
            end if
          end if
          exit repeat
        else
          if menufunc.char[j]="/" then
            setprop curritem, #shortcut, menufunc.char[j+1]
            exit repeat
          else
            put menufunc.char[j] after m
          end if
        end if
        
      end repeat
      addprop curritem, #item, m
      if the number of items of menuline>1 then
        hand=menuline.item[2]
        addprop curritem, #handler, hand
      else
        addprop curritem, #handler, ""
      end if
      add currmenu, curritem
    end if
  end repeat
  
  add pmenuitems, currmenu
  the mousedownscript="sendsprite (sprite("&me.spritenum&"), #stopmenu)"
  the keydownscript="if the shiftdown then sendsprite (sprite("&me.spritenum&"), #checkforshortcut)"
  pmouseselection=[0,0]
  popening=0
  
  
  sprite(me.spritenum).member.text=ptoptext
  sprite(pmenudownsprite).member=0
  the itemdelimiter=id
  pmenumember=new(#field)
  pmenumember.name="menu field"
  pmenumember.font=pfont
  pmenumember.fontsize=psize
  pmenumember.boxdropshadow=1
  pmenumember.boxtype=#fixed
  pmenumember.bgcolor=sprite(me.spritenum).member.bgcolor
end

on endsprite me
  erase pmenumember
end

on mousedown me
  if popening=0 then
    openamenu (me)
  end if
  
end


on mouseupoutside me
  stopmenu (me)
end


on exitframe me
  
  if popening=0 then exit
  if rollover(pmenudownsprite) then
    y=the mousev-sprite(pmenudownsprite).locv
    linenum=y/(pmenumember.lineheight)+1
    if linenum>pmenuitems[pmouseselection[2]].count then
      pmouseselection[1]=0
      exit
    end if
    
    if pmenuitems[pmouseselection[2]][linenum].enabled=true then
      
      if linenum=1 then startchar=1
      else
        startchar=(pmenumember.text.line[1..linenum-1]).length+2
      end if
      
      endchar=(pmenumember.text.line[1..linenum]).length+1
      hilite char startchar to endchar of field pmenumember
      pmouseselection[1]=linenum
    else
      pmenumember.media=pmenumember.media
      pmouseselection[1]=0
    end if
    
  else if rollover(me.spritenum) and the mouseword<>pmouseselection[2] then
    openamenu (me)
    
  else
    pmenumember.media=pmenumember.media
    pmouseselection[1]=0
  end if
end

on openamenu me
  popening=1
  m= the mouseword
  if m=-1 or m>pmenuitems.count then
    exit
  end if
  pmenumember.media=pmenumember.media
  pmouseselection=[0,m]
  if m=1 then c=1
  else
    d=1
    e=0
    repeat with c=1 to the number of chars of ptoptext
      if ptoptext.char[c]=" " and e=0 then
        d=d+1
        e=1
      else
        if ptoptext.char[c]<>" " then
          if d=m then exit repeat
          e=0
        end if
      end if
    end repeat
  end if
  z= charpostoloc(sprite(me.spritenum).member, c)
  l=z[1]
  t=sprite(me.spritenum).bottom
  r=l+30
  b=sprite(me.spritenum).member.lineheight*pmenuitems[m].count
  meloc=sprite(me.spritenum).loc
  mtext=""
  repeat with i=1 to pmenuitems[m].count
    put pmenuitems[m][i].item after mtext
    if pmenuitems[m][i].shortcut<>"" then put "  Shift+"&pmenuitems[m][i].shortcut after mtext
    if i  end repeat
  sprite(pmenudownsprite).member=pmenumember
  pmenumember.boxtype=#adjust
  pmenumember.text=mtext
  pmenumember.boxtype=#fixed
  put return after mtext
  pmenumember.text=mtext
  sprite(pmenudownsprite).rect=rect(l,t,r,b)+rect(meloc, meloc)
  repeat with i=1 to pmenuitems[m].count
    if pmenuitems[m][i].enabled=true then
      set the fontstyle of line i of field pmenumember = "bold"
    else
      set the fontstyle of line i of field pmenumember="plain"
    end if
  end repeat
  
end

on stopmenu me
  
  if popening=1 then
    popening=0
    sprite(pmenudownsprite).member=0
    
    if pmouseselection[1]<>0 then
      do pmenuitems[pmouseselection[2]][pmouseselection[1]].handler
    end if
    dontpassevent
  end if
end

on checkforshortcut me
  l=the key
  repeat with m in pmenuitems
    repeat with i in m
      if i.shortcut=l and i.enabled=true then
        do i.handler
      end if
    end repeat
  end repeat
end

on enableitem me, m, i
  if not integerP(m) or not integerP(i) then exit
  if m<0 or m>pmenuitems.count then exit
  if i<0 or i>pmenuitems[m].count then exit
  
  pmenuitems[m][i].enabled=true
end

on disableitem me, m, i
  if not integerP(m) or not integerP(i) then exit
  if m<0 or m>pmenuitems.count then exit
  if i<0 or i>pmenuitems[m].count then exit
  
  pmenuitems[m][i].enabled=false
end

on toggleitem me, m, i
  if not integerP(m) or not integerP(i) then exit
  if m<0 or m>pmenuitems.count then exit
  if i<0 or i>pmenuitems[m].count then exit
  
  pmenuitems[m][i].enabled=not pmenuitems[m][i].enabled
end

 


Upload Provided by ABCUpload ASP

Contact

MMI
22 West Court Sq
Suite 2C
Newnan, GA 30263
USA

Fax - (206) 339-5833

Send e-mail