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
China Multimedia Union
Vdig Xtra for Windows by Abstract Plane
Set Properties of a Flash Member
mySystem
Spell Check Xtra
keyboard input control
A* Pathfinder in Lingo
Alphamania
Follow the leader
Draw a line with lingo
 

 

 

Behavior Toggle Button

Added on 6/7/1999

 

Compatibilities:
behavior D6_5 Mac PC

This item has not yet been rated

Author: Markie (website)

Behaves like a "toggle", will be set in ON state and OFF state by clicking; also functions through lingo by handling message "Toggle" and "SetValue {0|1}", for example if this behavior was assigned to sprite 5, use sendsprite 5, #Toggle

property NormalMember, NormalMemberNum, ToggleMember, ImageCastLib
property Setting
property tracking

property onStateHandlerName
property offStateHandlerName

property myActiveMemory
property myMemory
property myUniqueID

on mouseDown me
  set the tracking of me = TRUE
  toggle me
end

on mouseEnter me
  if the tracking of me then    
    toggle me
  end if
end

on mouseLeave me
  if the tracking of me then
    toggle me
  end if
end

on mouseup me
  if the tracking of me then
    set the tracking of me = false
  end if
end

on mouseupOutside me
  if the tracking of me then
    set the tracking of me = false
  end if
end


on Toggle me
  setValue( me, NOT the Setting of me )
  if the setting of me = 0 then
    -- Run the handler specified for when the button is toggled off
    do the offStateHandlerName of me
  else
    -- Run the handler specified for when the button is toggled on
    do the onStateHandlerName of me
  end if
end

on SetValue me, v_me
  if v_me = 0 then
    -- setting "OFF"
    set the member of sprite the spriteNum of me = the normalMember of me
    set the Setting of me = 0
  else
    -- setting "ON"
    set the member of sprite the spriteNum of me = the toggleMember of me
    set the Setting of me = 1
  end if
  --  Save the state of the uniqe toggle
  if myActiveMemory then RememberValue( script "UI Toggle Button", the myUniqueID of me, the setting of me )
  updateStage
end

-- This method stores the current state of the toggle in a variable kept in the script, not the current instance
-- This avoids the use of a global, or any user-interaction other than uniquely labeling the toggle they wish to store the state of
-- Caveat here is the script **MUST** be available
-- It should reside in a shared file if moving between movies, or the variable will be lost
-- The uniqueID must truly be unique, or buttons will start to be mixed up
on RememberValue me, uniqueID, trueOrFalse
  if voidP( myMemory ) then set myMemory = [:]
  setAProp( myMemory, uniqueID, trueOrFalse )
end

-- Retrieve the current setting for the toggle
on RecallValue me, uniqueID
  if voidP( myMemory ) then
    set returnValue = 0
  else
    set returnValue = getAProp( myMemory , uniqueID )
    if voidP( returnValue ) then set returnValue = 0
  end if
  return returnValue
end

on beginSprite me
  set s = the spriteNum of me
  set the normalMemberNum of me = the memberNum of sprite s
  set the imageCastLib of me = the number of castLib the castLibNum of sprite s
  set the normalMember of me = member the normalMemberNum of me of castLib the imageCastLib of me
  set the toggleMember of me = member the toggleMemberNum of me of castLib the imageCastLib of me  
  if myActiveMemory then
    set oldSetting = RecallValue( script "UI Toggle Button", the myUniqueID of me )
    set the setting of me = oldSetting
  end if
  SetValue( me, the Setting of me )
end

on getPropertyDescriptionList
  if the currentspritenum = 0 then
    set memdefault = 0
  else
    set memref = the member of sprite the currentspritenum
    set castlibnum = the castlibnum of memref
    set memdefault = member (the membernum of member memref + 1) of castlib castlibnum
  end if
  set p_list = [:]
  setAProp( p_list, #toggleMemberNum, [ #comment: "Toggle Image:", #format: #graphic, #default:  memdefault ] )
  setAProp( p_list, #Setting, [ #comment: "Initially Toggled:", #format: #boolean, #default:  FALSE ] )
  setAProp( p_list, #onStateHandlerName, [ #comment: "Handler to run if on:", #format: #string, #default:  "Nothing" ] )
  setAProp( p_list, #offStateHandlerName, [ #comment: "Handler to run if off:", #format: #string, #default:  "Nothing" ] )
  setAProp( p_list, #myActiveMemory, [ #comment: "Save state information:", #format: #boolean, #default:  TRUE ] )
  setAProp( p_list, #myUniqueID, [ #comment: "Uniqe identifier for this toggle:", #format: #string, #default:  "" ] )
  return p_list
end

on SetToggleValue me, v_me
  -- duplicate of SetValue, used by radioButton behavior
  -- setting "OFF"
  if v_me = 0 then
    set the member of sprite the spriteNum of me = the normalMember of me
    set the Setting of me = 0
  else
    -- setting "ON"
    set the member of sprite the spriteNum of me = the toggleMember of me
    set the Setting of me = 1
  end if
  updateStage
end

on getBehaviorDescription
  return "Makes a sprite work as a toggle button with automatic highlighting and mouse tracking. The behavior responds when clicked, or when the SetToggleValue or Toggle messages are receieved. Use the the UI Radio Group behavior to control toggle buttons in radio button groups." & RETURN & "PARAMETERS:" & RETURN & "? Toggle Image - Choose the cast member to display when the button is toggled." & RETURN & "? Initially Toggled - Turn this option to make the button toggled when it first appears. (Not useful except for first time if saving state)" & RETURN & "? Handler to run if on - Replace this with the handler name to execute if the toggle is set to the ON position" & RETURN & "? Handler to run if off - Replace this with the handler name to execute if the toggle is set to the OFF position" & RETURN & "? Save state information - Leave this ON if you want the toggle to remember the setting and make it appear correct when returning from elsewhere" & RETURN & "? Unique Identifier - A name that you don't use elsewhere to UNIQUELY identify this particular toggle on this particular screen. (Used to restore the state)" & RETURN & "MESSAGES:"& RETURN & "? SetToggleValue {TRUE or FALSE} - Sets the toggle button."& RETURN & "? Toggle - Switches the toggle button state."
end

 


Contact

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

Send e-mail