---------------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------------
-- TOGLECAPTION --------------------------------------------------------------------------------------------
-- change the caption of a button on mouseup.(eg ON/OFF,...PLAY/STOP...etc.)
-- You can also change the textcolor...
--
-- november, 2000
--
-- Kurt Koenig * Belgium
---------------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------------
on getpropertydescriptionlist me
if not the currentSpriteNum then exit
pthisButn = sprite ( the currentSpriteNum ) . member
memberType = pThisButn.type
permittedType = RightMemberType(me)
if not permittedType.getPos(memberType) then
return ErrorAlert (me, #PDLError, permittedType)
end if
desclist = [:]
addprop desclist,¬
#pCaption1,¬
[¬
#comment: "The initial caption of this button:",¬
#format: #string, #default: ""¬
]
addprop desclist,¬
#pCaption2,¬
[¬
#comment: "The second caption of this button:",¬
#format: #string, #default: ""¬
]
addprop desclist,¬
#pChangeCol,¬
[¬
#comment: "Also change textcolor ?",¬
#format: #boolean, #default: ¬
FALSE¬
]
addprop desclist, ¬
#pNewCol,¬
[¬
#comment:"Change the textcolor to color (0-255):", ¬
#default:0, ¬
#format:#integer, ¬
#range:¬
[¬
#min:0,¬
#max:255¬
]¬
]
return desclist
end
on getBehaviorDescription me
return "¬
ChangeCaption"&RETURN&"¬
This behavior changes the caption of a button to"&RETURN&"¬
another string.You can also change the text color"&RETURN&"¬
By KK * Belgium"
end getBehaviorDescription
on Initialize me
pClicked = FALSE
TheSprite = sprite(me.spriteNum)
pThisButn = TheSprite.member
memberType = pThisButn.type
pOldCol = sprite(me.spriteNum). color
if not RightMemberType(me).getPos(memberType) then
ErrorAlert (me, #WrongMemberType, memberType)
end if
(pThisButn).text = pCaption1
(pThisButn). color = pOldCol
end Initialize
on RightMemberType me
return [#button]
end RightMemberType
on beginSprite me
Initialize me
end
on mouseup
pClicked = Not pClicked
if pClicked then
(pThisButn).text = pCaption2
else
(pThisButn).text = pCaption1
end if
if pClicked and pChangeCol then
(pThisButn).color = paletteindex (pNewCol)
else
(pThisButn).color = (pOldCol)
end if
end if
end
--based on James Newton's error handling code
on ErrorAlert me, theError, data
case theError of
#PDLError:
alert "¬
Error: This behavior works only with the following member type:"&RETURN&¬
RightMemberType(me)&RETURN&RETURN&"¬
Hit OK and then delete this behavior from the sprite. See the Help¬
system for details on deleting behaviors. KK"
if the optionDown then
return [ #PDLError:[ #comment: "ERROR: Wrong member type. Click 'Cancel'.", ¬
#format: #string, #range: [""], #default: ""]]
end if
otherwise
behaviorName = string (me)
delete word 1 of behaviorName
delete the last word of behaviorName
delete the last word of behaviorName
case data.ilk of
#void: data = ""
#symbol: data = "#"&data
end case
case theError of
#WrongMemberType:
alert "BEHAVIOR ERROR: Frame "&the frame&", Sprite "&me.spriteNum&RETURN&RETURN&"¬
Behavior "&behaviorName&" only functions with the following member type: "&¬
RightMemberType()&RETURN&RETURN&¬
"Current type = "&data
halt
end case
end case
end ErrorAlert
Contact
MMI
36 South Court Sq
Suite 300
Newnan, GA 30263
USA