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
Amara Flash Photo Animation Software
Ripple Follow Mouse on Rollover-Alphamania
ToolTips for Shockwave 3D
Title Bar MIAW
Play different Movies For Different Game Levels
Shadow Maker
Icon Shop
Director MX Bugs: editable text and on prepareFrame
Stub Projector
Mile High Table O'Products
 

 

 

Behavior Tristate button with caption

Added on 12/2/2002

 

Compatibilities:
behavior D8 D8_5 D9 Mac PC Shockwave

This item has not yet been rated

Author: barb3tta

Create a tristate button with a caption on it and resize the button to view all the text. Based on a tristate button posted on this site. I simply add the caption functionality!

on getBehaviorDescription me
  return "Crea bottone"&RETURN&RETURN&
         "Crea un bottone tristate e ci aggiunge il testo."&RETURN&RETURN&
         "PARAMETRI:"&RETURN&
         "Testo del bottone"&RETURN&
         "* Membro per il bottone giu"&RETURN&
         "* Membro per il bottobe evidenziato"&RETURN&RETURN&
         "Testo del bottone" & RETURN &
         "Carattere del testo" & RETURN &
         "Dimensione del testo" & RETURN &
         "Dimensione bordi laterali" & RETURN &
         "Dimensione bordo inferiore e superiore" & RETURN &
         "se non vengono specificati i membri si cercheranno i membri 'BottoneGiu' e 'BottoneOver'"
end


on getBehaviorTooltip me
  return "Usare con le sprite grafiche."&RETURN&RETURN&"Crea un bottone tristate e aggiunge il testo."
end getBehaviorTooltip

property spriteNum
property myCaption
property myFont
property myFontSize
property mySprite
property myBorderHor
property myBorderVer
property myStandardMember
property myRollovermember
property myDownMember
property active
property cyclegraphics
property anotherButtonActive

on createCaption (caption)
  --cerca il primo canale libero per inserirci la sprite
  i = 1
  repeat while i <= the lastchannel
    if sprite(i).type = 0 then
      exit repeat
    else
      i = i + 1
    end if
  end repeat
  if i > the lastchannel then exit
  NewSprite = sprite(i)
  --crea il membro di testo
  CaptionMember = new(#text, castLib the castLibNum of member myStandardMember)
  CaptionMember.width = 1
  CaptionMember.wordwrap = false
  CaptionMember.alignment = #center
  CaptionMember.text = caption & " "
  CaptionMember.fontSize = myFontSize
  CaptionMember.font = myFont
  CaptionMember.boxType = #adjust
  CaptionMember.width = gettotalwidth(captionmember)
  CaptionMember.editable = false
  --crea la sprite
  puppetsprite i , true
  NewSprite.member = CaptionMember
  --  NewSprite.width = CaptionMember.width
  --  NewSprite.height = CaptionMember.height
  NewSprite.ink=36
  --posiziona la sprite
  NewSprite.loc = point (mysprite.left + myborderhor, mysprite.top + myborderver)
  --ridimensiona il bottone
  mySprite.bottom = NewSprite.bottom + myborderver
  mySprite.right = NewSprite.right + myborderhor
  NewSprite.Visible = true  
end createCaption

-- This handler calculates the total length of a field.
-- manca l'ultimo carattere
on getTotalWidth textField
  set totalChars to length(the text of member textField)
  set currentPoint to charPosToLoc(member textField, totalChars)
  set currentWidth to the locH of currentPoint
  return(currentWidth)
end



on beginSprite me
  --memorizza la sprite da usare per il bottone in stato normale
  mySprite         = sprite (me.spriteNum)
  myStandardMember = mySprite.member
  active = false
  anotherButtonActive = false
  --crea il testo sopra la sprite e ridimensiona la sprite (se è stato immesso del testo)
  if myCaption <>"" then createCaption (myCaption)
end


on mouseEnter me
  
  if the blend of sprite mysprite = 100 and not the cyclegraphics of me then
    if the active of me then
      mySprite.member = myDownMember
    else
      if not the anotherButtonActive of me then
        mySprite.member = myRolloverMember
        updateStage
      end if
    end if
  end if
  
end mouseEnter


on mouseLeave me
  
  if the blend of sprite mysprite = 100 and not the cyclegraphics of me then
    if not anotherButtonActive then
      mySprite.member = myStandardMember
      updateStage
    end if
  end if
  
end mouseLeave


on mouseWithin me
  
  if the blend of sprite mysprite = 100 and not the cyclegraphics of me then
    if not the active of me and not anotherButtonActive then
      mySprite.member = myRolloverMember
      updateStage
    end if
  end if
  
end mouseWithin


on mouseDown me
  
  if the blend of sprite mysprite = 100 and not the cyclegraphics of me then
    if not the active of me and not anotherButtonActive then
      set mySprite.member = myDownMember
      set the active of me = true
      sendAllSprites(#pi_ButtonMouseDownInitiated, me.spritenum)
      updateStage
    end if
  end if
  
end mouseDown


on mouseUp me
  
  if the blend of sprite mysprite = 100 and not the cyclegraphics of me then
    if the active of me then
      set mySprite.member = myStandardMember
      set the active of me = false
      updateStage
      sendAllSprites(#pi_ButtonMouseDownComplete)
    end if
  end if
  
end mouseDown


on mouseUpOutside me
  
  if the blend of sprite mysprite = 100 and not the cyclegraphics of me then
    if the active of me then
      set mySprite.member = myStandardMember
      set the active of me = false
      updateStage
      sendAllSprites(#pi_ButtonMouseDownComplete)
    end if
  end if
  
end mouseUpOutside  


-- user defined handlers

on pi_ButtonMouseDownInitiated me, initiatingSprite
  
  -- another button on this frame has initiated a mouseDown event
  -- set anotherButtonActive property to true
  -- ignore mouse events until the current mouse activity is complete
  
  if initiatingSprite <> me.spritenum then
    set the anotherButtonActive of me = true
  end if
  
end


on pi_ButtonMouseDownComplete me
  
  -- another button on this frame has completed a mouseDown event
  -- set anotherButtonActive property to false
  -- begin accepting mouse events again
  set the anotherButtonActive of me = false
  
end

on CycleGraphics_ToggleLoop me, trueOrFalse
  
  -- this method is for using this rollover along with the CycleGraphics behavior
  -- if this sprite is currently cycling graphics (such as a flashing button)
  -- then the cyclegraphics property is set to true so that the rollover won't interfere
  -- with the flashing of the sprite
  
  if voidP (trueOrFalse) then
    cyclegraphics = not cyclegraphics
  else if ilk (trueOrFalse) <> #integer then
    -- Error check
    return #invalidTypeError
  else
    cyclegraphics = trueOrFalse
  end if
  
end


on getPropertyDescriptionList
  if the currentSpriteNum = 0 then exit
  theMember       = sprite(the currentSpriteNum).member
  theMemberNumber = theMember.number
  
  
  return [#myDownMember: [#comment: "Quale membro usare se il bottone è premuto?", #format: #graphic, #default: member ("BottoneGiu")] ,
          #myRolloverMember:[#comment: "Quale membro usare se si passa sul bottone?", #format: #graphic, #default: member ("BottoneOver")],
          #myCaption: [#comment: "Testo del bottone", #format: #string, #default: ""] ,
          #myFont: [#comment: "Carattere del testo", #format: #string, #default: "Arial"] ,
          #myFontSize: [#comment: "Dimensione del testo", #format: #integer, #default: 10],
          #myBorderHor:[#comment: "Dimensione bordi laterali", #format: #integer, #default: 5],
          #myBorderVer:[#comment: "Dimensione bordo inferiore e superiore", #format: #integer, #default: 5]]
  
end getPropertyDescriptionList

 


Contact

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

Send e-mail