-- RADIO BUTTON ACTION -- -- -- © May 2001, James Newton -- -- This behavior allows sprites with the Radio Button States behavior -- to execute a given action on mouseUp. -- PROPERTY DECLARATIONS -- property buttonAction property callHandler property callObject property myRadioInstances -- [] -- SPRITE EVENTS -- on beginSprite(me) callObjects = me.getLocalizedString(#callObjects, FALSE) callObject = callObjects.getOne(callObject) end beginSprite on endSprite(me) if listP(myRadioInstances) then myRadioInstances.deleteAll() end if end endSprite -- EVENT HANDLER -- on mouseUp(me) case callObject of #movie: sendSprite(0, callHandler, buttonAction) #sprite: tScriptInstanceList = sprite(me.spriteNum).scriptInstanceList call(callHandler, tScriptInstanceList, buttonAction) #sendAllSprites: sendAllSprites(callHandler, buttonAction) #call: if not listP(myRadioInstances) then myRadioInstances = [] sendAllSprites(#getReference, callHandler, myRadioInstances) end if call(callHandler, myRadioInstances, buttonAction) #actorList: call(callHandler, the actorList, buttonAction) end case end mouseUp -- UTILITY HANDLER -- on getDefaultAction(me) ---------------------------------------------- -- Called by getPropertyDescriptionList() -- -- RETURNS: the value of the myAction property set in a Radio Button -- States behavior on the same sprite... or a default value if no -- myAction property is found. -------------------------------------------------------------------- if the currentSpriteNum then behaviors = sprite(the currentSpriteNum).scriptList i = behaviors.count repeat while i parameters = value(behaviors[i][2]) if ilk(parameters, #propList) then defaultAction = parameters[#myAction] if symbolP(defaultAction) then return defaultAction end if end if i = i - 1 end repeat end if -- The script is being recompiled, or no "Radio Button States" -- behavior is attached to the same sprite return #radioButtonAction end getDefaultAction on getLocalizedString(me, stringSymbol, asLinearList) ---------------- -- Called by getPropertyDescriptionList() and initialize() -- -- PARAMETERS: -- should be a symbol -- may be TRUE when this handler is called by -- getPropertyDescriptionList() -- -- RETURNS: a localized string defined by -- -- NOTE: Storing all strings in one place makes it easy to -- localize the behavior. -- -- The getPropertyDescriptionList() handler may require a list of -- strings. These may need to be converted to a language-neutral -- #symbol when the behavior is used. In this case, this handler -- can return a property list where the properties are symbols and -- the values are localized strings. The getPD() handler can -- specify that this list be converted to a linear list for display, -- by setting to TRUE. The initialize() handler, -- called on beginSprite, can recuperate the full property list and -- use the following code to convert the appropriate string to a -- symbol: -- -- propertyList = me.getLocalizedString(#propList, FALSE) -- getPDLValue = propertyList.getOne(getPDLValue) -------------------------------------------------------------------- case stringSymbol of #callHandler: localizedString = "When this button is clicked call the handler" #defaultHandler: localizedString = #radioButtonClicked #callObject: localizedString = "which is located" #callObjects: localizedString = [ \ #movie: "in a Movie Script", \ #sprite: "in another behavior on this sprite", \ #sendAllSprites: "in behaviors on other sprites", \ #call: "in all behaviors subscribed by #getReference", \ #actorList: "in an instance on the actorList" \ ] #buttonAction: localizedString = "[Optional] Parameter for call:" otherwise: -- Unexpected value localizedString = string(stringSymbol) end case if ilk(localizedString, #propList) then if asLinearList then -- Convert a property list to a linear list for getPDL() temp = localizedString localizedString = [] counter = temp.count repeat with i = 1 to counter localizedString[i] = temp[i] end repeat end if end if return localizedString end getLocalizedString -- BEHAVIOR DESCRIPTION AND PARAMETERS -- on isOKToAttach(me, spriteType, spriteNumber) -- Don't allow the behavior to be attached to a frame return spriteType = #graphic end isOKToAttach on getPropertyDescriptionList(me) propertiesList = [:] callObjects = me.getLocalizedString(#callObjects, TRUE) propertiesList[ \ #callHandler] = [ \ #comment: me.getLocalizedString(#callHandler), \ #format: #symbol, \ #default: me.getLocalizedString(#defaultHandler) \ ] propertiesList[ \ #callObject] = [ \ #comment: me.getLocalizedString(#callObject), \ #format: #symbol, \ #range: callObjects, \ #default: callObjects[3] \ ] propertiesList[ \ #buttonAction] = [ \ #comment: me.getLocalizedString(#buttonAction), \ #format: #symbol, \ #default: me.getDefaultAction() \ ] return propertiesList end getPropertyDescriptionList on getBehaviorTooltip(me) return \ "Allows sprites with the Radio Button States"&RETURN&\ "behavior to execute a given action on mouseUp." end getBehaviorTooltip