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
Tristate button with caption
Mouse click or Key press
Custom Alert
cXtraPieChart
Library dmm_cdext - Audio CD Controller
Space Invaders
NAB - 'Not Another Button'
Regular expressions
Get the computer name of user
Rename for lingo animations
 

 

 

Behavior NAB - 'Not Another Button'

Added on 6/10/1999

 

Compatibilities:
behavior D6_5 Mac PC

This item has not yet been rated

Author: ToddLevy

This is a pretty complex button behavior. See the behavior description for some usage tips and instructions. Bug reports are more than welcome, as are suggestions and lingo advice.

property pTempActionHandler         -- the temp main action handler
property pActionHandler             -- the main action handler
property pSpriteNum                 -- the button's sprite
property pDeactivateHandler         -- the deactivation handler
property pUpMember                  -- the button's plain image
property pRollMember                -- the button's roll image
property pDownMember                -- the button's down image
property pToggleOnMember            -- the button's active image
property pToggleOnRollMember        -- the button's active roll image
property pToggleOnDownMember        -- the button's active down image
property pActivateAction            -- do action on up or down
property pMouseInButtonHandler      -- handler when mouse within
property pButtonDownHandler         -- handler when mouse down
property pButtonUpHandler           -- handler when mouse up
property pButtonEnterHandler        -- handler when mouse enters
property pButtonLeaveHandler        -- handler when mouse leaves
property pNumOfStates               -- num of button states
property pToggleStatus              -- button toggled on or off
property pRepeatingButton           -- repeat yes or no
property pMaskedButton              -- button has a mask

on beginSprite me
  set pSpriteNum to the spriteNum of me
  -- BUTTON WITH OVER FOUR STATES HAS
  -- AN ACTIVATE AND DEACTIVATE HANDLER
  -- OTHER BUTTONS HAVE ONLY AN ACTION HANDLER
  if pNumOfStates >= #4 then
    set pActionHandler = item 1 of pTempActionHandler
    set pDeactivateHandler = item 2 of pTempActionHandler
  else
    set pActionHandler = item 1 of pTempActionHandler
  end if
  -- INIT THE DIFFERENT BUTTON MEMBERS
  if pMaskedButton = "#FALSE" then
    set pUpMember = the memberNum of sprite pSpriteNum
    set pDownMember = pUpMember + 1
    if pNumOfStates >= #3 then
      set pRollMember = pUpMember + 2
    end if
    if pNumOfStates >= #4 then
      set pToggleOnMember = pUpMember + 3
    end if
    if pNumOfStates >= #5 then
      set pToggleOnDownMember = pUpMember + 4
    end if
    if pNumOfStates >= #5 then
      set pToggleOnRollMember = pUpMember + 5
    end if
  else if pMaskedButton = "#TRUE" then
    set pUpMember = the memberNum of sprite pSpriteNum
    set pDownMember = pUpMember + 2
    if pNumOfStates >= #3 then
      set pRollMember = pUpMember + 4
    end if
    if pNumOfStates >= #4 then
      set pToggleOnMember = pUpMember + 6
    end if
    if pNumOfStates >= #5 then
      set pToggleOnDownMember = pUpMember + 8
    end if
    if pNumOfStates >= #5 then
      set pToggleOnRollMember = pUpMember + 10
    end if
  end if        
  -- INIT TOGGLE TO INACTIVE
  set pToggleStatus = #inactive
  puppetSprite pSpriteNum,TRUE
end

on mouseUp me
  -- THE BUTTON IMAGE SHOULD BE UP IF < 4 STATES
  if pNumOfStates < #3 then
    set the memberNum of sprite pSpriteNum = pUpMember
  end if
  -- THE BUTTON IMAGE SHOULD BE ROLLED
  if pNumOfStates >= #3 then
    set the memberNum of sprite pSpriteNum = pRollMember
  end if
  -- ANY UP SCRIPT SHOULD BE EXECUTED
  do pButtonUpHandler
  -- IF ACTIVATE ON UP, DO SO
  if pActivateAction = #up then
    NAB_activateButton me
  end if
  -- A LESS THAN FOUR GREATER THAN ZERO STATE REPEATING BUTTON
  -- SHOULD BE SET TO NOT REPEAT
  if pNumOfStates < #4 AND pNumOfStates > #0 AND pRepeatingButton = #now then
    set pRepeatingButton = #notNow
  end if
end

on mouseUpOutside me
  -- THE MOUSE WENT UP OUTSIDE OF A BUTTON
  -- ANY NON ACTIVE BUTTON SHOULD BE UP
  if pToggleStatus <> #active then set the memberNum of sprite pSpriteNum = pUpMember
  -- A LESS THAN FOUR STATE REPEATING BUTTON
  -- SHOULD BE SET TO NOT REPEAT
  if pNumOfStates < #4 AND pRepeatingButton = #now then
    set pRepeatingButton = #notNow
  end if
end

on mouseDown me
  -- THE BUTTON IMAGE SHOULD BE TOGGLE AND DOWN
  if pNumOfStates >= #5 AND pToggleStatus = #active then ¬
                     set the memberNum of sprite pSpriteNum = pToggleOnDownMember
  -- THE BUTTON IMAGE SHOULD BE DOWN
  if pNumOfStates >= #2 AND pToggleStatus = #inactive then ¬
                 set the memberNum of sprite pSpriteNum = pDownMember
  -- ANY DOWN SCRIPT SHOULD BE EXECUTED
  do pButtonDownHandler
  -- IF ACTIVATE ON DOWN, DO SO
  if pActivateAction = #down then NAB_activateButton
end

on mouseEnter me
  -- DO ENTER HANDLER
  do pButtonEnterHandler
  if pNumOfStates >= #3 then
    -- IF AT LEAST THREE STATES
    if pNumOfStates = #4 then
      -- IF THE BUTTON IS FOUR STATES (INACTIVE ROLLOVER)
      if pToggleStatus <> #active then
        -- IF ITS INACTIVE GO TO STANDARD ROLLOVER
        set the memberNum of sprite pSpriteNum = pRollMember
      end if
    else if pNumOfStates = #5 then
      -- IF THE BUTTON IS FIVE STATES (INACTIVE AND ACTIVE ROLLOVER)
      if pToggleStatus = #active then
        -- IF ITS ACTIVE THE GO TO DOWN BUTTON
        set the memberNum of sprite pSpriteNum = pToggleOnRollMember
      else
        -- IF ITS INACTIVE GO TO STANDARD ROLLOVER
        set the memberNum of sprite pSpriteNum = pRollMember
      end if
    else
      -- THE BUTTON IS THREE STATES (ROLLOVER)
      set the memberNum of sprite pSpriteNum = pRollMember
    end if        
  end if
  if pNumOfStates = #0 then
    NAB_activateButton me  
  end if
end

on mouseWithin me
  do pMouseInButtonHandler
end

on mouseLeave me
  -- DO LEAVE HANDLER
  do pButtonLeaveHandler
  -- WHEN MOUSE LEAVES BUTTON
  if pToggleStatus = #active then
    -- IF THE BUTTON IS ACTIVE THEN PUT IT TO ACTIVE MEMBER
    set the memberNum of sprite pSpriteNum = pToggleOnMember
  else
    -- OTHERWISE THE BUTTON IMAGE SHOULD BE UP
    set the memberNum of sprite pSpriteNum = pUpMember
    updateStage
  end if
  -- A LESS THAN FOUR STATE REPEATING BUTTON
  if pNumOfStates < #4 then
    -- SHOULD BE SET TO NOT REPEAT
    if pRepeatingButton = #now then
      set pRepeatingButton = #notNow
    end if
  end if
end

on exitFrame me
  -- IF BUTTON IS IN REPEAT STATE DO THE ACTION HANDLER NOW
  if pRepeatingButton = #now then do pActionHandler
end

on NAB_activateButton me
  -- ON AN ACTIVATE MESSAGE
  -- IF THE BUTON IS NOT CURRENTLY ACTIVE
  if pToggleStatus <> #active then
    if pNumOfStates >= #4 then
      -- AND IT HAS FOUR OR MORE STATES
      -- THE BUTTON IMAGE SHOULD BE TOGGLE ON
      set the memberNum of sprite pSpriteNum = pToggleOnMember
      set pToggleStatus = #active
    end if
    -- IF ITS A REPEATING BUTTON THEN SET IT TO REPEAT
    if pRepeatingButton = TRUE OR pRepeatingButton = #notNow then
      set pRepeatingButton = #now
      exit
    end if
    -- DO THE ACTION HANDLER NOW
    do pActionHandler
  else
    -- IF THE BUTTON IS CURRENTLY ACTIVE THEN
    -- THE BUTTON IMAGE SHOULD BE UP
    set the memberNum of sprite pSpriteNum = pUpMember
    -- TOGGLE STATUS SHOULD BE INACTIVE
    set pToggleStatus = #inactive
    -- IF ITS A REPEATING BUTTON SET IT TO NOT REPEAT
    if pRepeatingButton = #now then set pRepeatingButton = #notNow
    -- IT SHOULD DO THE DEACTIVATE SCRIPT
    do pDeactivateHandler
  end if
end

on getPropertyDescriptionList
  
  set theProps to [:]
  
  set typeProps to [#comment:"Number Of States:",#format:#string,#range:[#0,#1,#2,#3,#4,#5,#field_lengthener_dont_select],#default:"#1"]
  addProp theProps, #pNumOfStates, typeProps
  
  set typeProps to [#comment:"Action Handler:",#format:#string,#default:""]
  addProp theProps, #pTempActionHandler, typeProps
  
  set typeProps to [#comment:"Mouse Within Handler:",#format:#string,#default:""]
  addProp theProps, #pMouseInButtonHandler, typeProps
  
  set typeProps to [#comment:"Button Down Handler:",#format:#string,#default:""]
  addProp theProps, #pButtonDownHandler, typeProps
  
  set typeProps to [#comment:"Button Up Handler:",#format:#string,#default:""]
  addProp theProps, #pButtonUpHandler, typeProps
  
  set typeProps to [#comment:"Mouse Enter Handler:",#format:#string,#default:""]
  addProp theProps, #pButtonEnterHandler, typeProps
  
  set typeProps to [#comment:"Mouse Leave Handler:",#format:#string,#default:""]
  addProp theProps, #pButtonLeaveHandler, typeProps
  
  set typeProps to [#comment:"Activate Action:",#format:#string,#range:[#up,#down],#default:"#down"]
  addProp theProps, #pActivateAction, typeProps
  
  set typeProps to [#comment:"Repeating:",#format:#boolean,#default:"#FALSE"]
  addProp theProps, #pRepeatingbutton, typeProps
  
  set typeProps to [#comment:"Mask:",#format:#boolean,#default:"#FALSE"]
  addProp theProps, #pMaskedButton, typeProps
  
  return theProps
  
end

on getBehaviorDescription
  return string("This button behavior does the following..."&RETURN&¬
           "accepts a number of states"&RETURN&¬
           "  #0 - the button will perform the activate action when the mouse enters the button"&RETURN&¬
           "  #1 - This button must be clicked to activate, but still has only one image"&RETURN&¬
           "  #2 - This button also has a down image."&RETURN&¬
           "  #3 - This button also has a down and rolled over image."&RETURN&¬
           "  #4 - This button also has an additional toggled-on image."&RETURN&¬
           "  #5 - This button also has an additional rolled and down image for toggled-on. Activate on up is recommended"&RETURN&¬
           "It uses up to six images"&RETURN&¬
           "  1st - the  normal unrolled or clicked button"&RETURN&¬
           "  2nd - the down state of a 2 or 3 state button, an toggle off or on 4 state button, and a toggle off 5 state button"&RETURN&¬
           "  3rd - the rolled over state for 3 states, and the toggled off rolled over state for 4 and 5 state buttons"&RETURN&¬
           "  4th - the toggled-on state of 4 or 5 state buttons"&RETURN&¬
           "  5th - the down state of an toggled-on 4 or 5 state button"&RETURN&¬
           "  6th - the toggled-on rolled over state for 5 state buttons"&RETURN&¬
           "Action Handler"&RETURN&¬
           "  The primary action for a button to do when it executes. Separate two by a comma for 4 and 5 state buttons to have an activate and deactivate action."&RETURN&¬
           "The following five handlers are independent of the number of states the button has."&RETURN&¬
           "Within Handler"&RETURN&¬
           "  The handler when the mouse is within the button."&RETURN&¬
           "Mouse Up Handler"&RETURN&¬
           "  The handler when the mouse goes up inside the button. Useful for click sounds."&RETURN&¬
           "Mouse Down Handler"&RETURN&¬
           "  The handler when the mouse goes down inside the button. Useful for click sounds."&RETURN&¬
           "Mouse Enter Handler"&RETURN&¬
           "  The handler when the mouse enters the button. For example to have the button animate on rollover."&RETURN&¬
           "Mouse Leave Handler"&RETURN&¬
           "  The handler when the mouse leaves the button."&RETURN&¬
           "Using the activate action choice"&RETURN&¬
           "  A button has a primary handler that is its activation handler. This pop-up determines whether it executes this handler on mouse up or down."&RETURN&¬
           "Using the repeating checkbox"&RETURN&¬
           "  Almost any button can repeatedly perform its activate action. For example, a zero state button will perform repeatedly while the mouse is inside it. A one, two or three state button will repeat while the mouse is down on it, provided the activate action is down. A four or five state button will repeat while in its toggle-on state."&RETURN&¬
           "Using the masking checkbox"&RETURN&¬
           "  Click this if the castmembers for the button each have a bitmap mask in the next spot in the cast, and are using the mask in  k effect."&RETURN&¬
             "Drop this on a button and go nuts.")
end  

 


Contact

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

Send e-mail