-- TOGGLE BUTTON STATES -- -- -- -- PROPERTIES -- property buttonID property activeFlag property stateFlag property offState property onState property switchState property nullState property handler property location property mySprite property myMouseDown -- SPRITE EVENTS -- on beginSprite(me) mySprite = sprite(me.spriteNum) if activeFlag then if stateFlag then mySprite.member = onState else mySprite.member = offState end if else mySprite.member = nullState end if end beginSprite -- EVENT HANDLERS -- on mouseEnter(me) if not activeFlag then -- Prevent the mouseEnter from passing to later behaviors on -- the same sprite stopEvent exit end if if not myMouseDown then exit end if if stateFlag then mySprite.member = switchState else mySprite.member = onState end if end mouseEnter on mouseLeave(me) if not activeFlag then -- Prevent the mouseLeave from passing to later behaviors on -- the same sprite stopEvent exit end if if not myMouseDown then exit end if if stateFlag then mySprite.member = onState else mySprite.member = offState end if end mouseLeave on mouseDown(me) if not activeFlag then -- Prevent the mouseDown from passing to later behaviors on -- the same sprite stopEvent exit end if myMouseDown = TRUE if stateFlag then mySprite.member = switchState else mySprite.member = onState end if end mouseDown on mouseUp(me) if not activeFlag then -- Prevent the mouseUp from passing to later behaviors on -- the same sprite in all circumstances. This allows the -- behavior to customize the mouseUp message stopEvent exit end if if not myMouseDown then exit end if myMouseDown = FALSE -- Show appropriate image stateFlag = not stateFlag if stateFlag then mySprite.member = onState else mySprite.member = offState end if case location of "a movie script": sendSprite(0, handler, stateFlag) "a behavior on the same sprite": behaviors = mySprite.scriptInstanceList call(handler, behaviors, stateFlag) "behaviors on other sprites": sendAllSprites(handler, stateFlag) "an instance on the actorList": call(handler, the actorList, stateFlag) end case end mouseUp on mouseUpOutside(me) if not activeFlag then -- Prevent the mouseUpOutside from passing to later behaviors on -- the same sprite stopEvent exit end if myMouseDown = FALSE end mouseUpOutside -- PUBLIC METHODS -- on Toggle_SetState(me, trueOrFalse, ID) -- Toggles the button's stateFlag property between ON and OFF -- states. If the button is currently inactive, the new state is -- set, but the button will not adopt the appropriate image until it -- has been reactivated using Toggle_Active. -- Both trueOrFalse and ID may be void. If ID is a string, it must -- be correspond to either buttonID -- -- If trueOrFalse is not an integer then stateFlag takes on the -- opposite boolean value... unless trueOrFalse is symobl which -- corresponds to neither myCommand nor myAction, in which case the -- call is ignored. if stringP(ID) then case ID of buttonID: -- continue otherwise -- This instance is not concerned by the Toggle_SetState event exit end case end if case ilk(trueOrFalse) of #integer: -- Ensure that trueOrFalse is either 1 (TRUE) or 0 (FALSE) trueOrFalse = (trueOrFalse <> 0) if stateFlag = trueOrFalse then -- Respect the status quo exit end if -- Toggle to the new value stateFlag = trueOrFalse #string: case trueOrFalse of buttonID: -- No new value is given: toggle to the opposite value stateFlag = not stateFlag otherwise -- Instance is not concerned by the Toggle_SetState event exit end case otherwise -- No new value is given: toggle to the opposite value stateFlag = not stateFlag end case if not activeFlag then -- New value will only take effect once button has been activated exit end if -- Show the appropriate image for the state of the button if stateFlag then mySprite.member = onState else mySprite.member = offState end if end Toggle_SetState on Toggle_Active(me, trueOrFalse, ID) -- Toggles the button's activeFlag between Enabled and Disabled -- states. Both trueOrFalse and ID may be void. If ID is a string, -- it must correspond to buttonID -- If trueOrFalse is not an integer then activeFlag takes on the -- opposite boolean value... unless trueOrFalse is symbol which -- corresponds neither to myCommand nor myAction, in which case the -- call is ignored. if symbolP(ID) then case ID of buttonID: -- continue otherwise -- This instance is not concerned by the Toggle_Active event exit end case end if case ilk(trueOrFalse) of #integer: -- Ensure that trueOrFalse is either 1 (TRUE) or 0 (FALSE) trueOrFalse = (trueOrFalse <> 0) if activeFlag = trueOrFalse then -- Respect the status quo exit end if -- Toggle to the new value activeFlag = trueOrFalse #string: case trueOrFalse of buttonID: -- No new value is given: toggle to the opposite value activeFlag = not activeFlag otherwise -- This instance is not concerned by the Toggle_Active event exit end case otherwise -- No new value is given: toggle to the opposite value activeFlag = not activeFlag end case -- Show the appropriate image for the state of the button if activeFlag then if stateFlag then mySprite.member = onState else mySprite.member = offState end if else mySprite.member = nullState end if end Toggle_Active -- UTILITY HANDLERS -- on getDefaultMembers(me) -------------------------------------------- -- Called by addMemberProperties() -- -- * Returns a list of default members for the Behavior -- Parameters dialog. This assumes that the current member of the -- sprite is the offState member, and that the other members to -- be associated with the sprite are to be found in the following -- member slots: off state, on state, switch state, null state. -------------------------------------------------------------------- if not the currentSpriteNum then -- Director is simply recompiling scripts: return dummy -- values return [member 1, member 1, member 1, member 1] else -- Return default members for the Behavior Parameters dialog offStateMember = sprite(the currentSpriteNum).member memberType = offStateMember.type theNumber = offStateMember.number -- Propose the following members in the same cast for the other -- button states... if they are of the same membertype. Otherwise -- propose the standard member onStateMember = member(theNumber + 1) if onStateMember.type <> memberType then onStateMember = offStateMember end if switchMember = member(theNumber + 2) if switchMember.type <> memberType then switchMember = offStateMember end if nullMember = member(theNumber + 3) if nullMember.type <> memberType then nullMember = offStateMember end if return [ \ offStateMember, \ onStateMember, \ switchMember, \ nullMember \ ] end if end getDefaultMembers -- BEHAVIOR DESCRIPTION AND PARAMETERS -- on isOKToAttach (me, spriteType, spriteNumber) -- Accept all graphic sprites return (spriteType = #graphic) end isOKToAttach on getBehaviorToolTip(me) return \ ""&RETURN&\ "" end on getBehaviorDescription(me) return \ "TOGGLE BUTTON STATES"&RETURN&RETURN&\ "" end getBehaviorDescription on getPropertyDescriptionList(me) propertiesList =[:] defaultValues = me.getDefaultMembers() propertiesList[ \ #buttonID] = [ \ #comment: "ID string used to identify this button", \ #format: #string, \ #default: "Button "&the currentSpriteNum \ ] propertiesList[ \ #activeFlag] = [ \ #comment: "Button is initially active?", \ #format: #boolean, \ #default: TRUE \ ] propertiesList[ \ #stateFlag] = [ \ #comment: "Button is initially selected?"&RETURN&\ "----------------------------------------------", \ #format: #boolean, \ #default: FALSE \ ] -- Image members propertiesList[ \ #offState] = [ \ #comment: "Image for off state", \ #format: #bitmap, \ #default: defaultValues[1] \ ] propertiesList[ \ #onState] = [ \ #comment: "Image for on state", \ #format: #bitmap, \ #default: defaultValues[2] \ ] propertiesList[ \ #switchState] = [ \ #comment: "Image for switching-off state", \ #format: #bitmap, \ #default: defaultValues[3] \ ] propertiesList[ \ #nullState] = [ \ #comment: "Image for inactive state"&RETURN&\ "----------------------------------------------", \ #format: #bitmap, \ #default: defaultValues[4] \ ] -- Call back propertiesList[ \ #handler] = [ \ #comment: "On mouseUp, call the handler", \ #format: #symbol, \ #default: #toggle \ ] propertiesList[ \ #location] = [ \ #comment: "which appears in", \ #format: #string, \ #range: [ \ "a movie script", \ "a behavior on the same sprite", \ "behaviors on other sprites", \ "an instance on the actorList" \ ], \ #default: "a behavior on the same sprite" \ ] return propertiesList end getPropertyDescriptionList