property pSliderSprite -- the slider widget sprite property pYmin, pYmax -- movement limit values for the widget property pDragging -- is the widget sprite being dragged? property pOffY -- vertical offset between mouse click and sprite location property pMaxNum -- the maximum value returned by the slider property pUseTextMember -- show text cast member when slider is active? property pTextMember -- the text member to use to display the slider's output property pTextSprite -- the sprite channel of the text member that displays the slider value property pTextSpriteLoc -- offscreen location of the text sprite property pTextSpriteOffset -- a point representing the offset of the text member that displays a value property pValueString -- the current slider value as a string on beginSprite me pSliderSprite = sprite(me.spriteNum) spLine = sprite(me.spritenum - 1) -- slider track is in the previous sprite channel from this one pTextSprite = sprite(me.spritenum + 1) -- text member is in the next sprite channel from this one pTextSpriteLoc = sprite(pTextSprite).loc -- original location of the text sprite -- set Y constraints for range of movement halfWidgetHeight = pSliderSprite.height / 2 pYmin = spLine.top + halfWidgetHeight pYmax = spLine.bottom - halfWidgetHeight end -- Y SLIDER BEHAVIOR -- -- This behavior should be attached to the moveable widget. -- -- There are three parts to a slider: -- 1) The moveable slider widget. -- 2) The "track" the widget slides along. -- 3) The text member that displays the slider's value. -- 4) A global variable that stores the slider's value. By default the variable is named: _global.sliderValue2 -- -- This script looks for the track of the slider in a sprite channel -- that is one less than this one, and the text member sprite to be -- in a sprite channel that is one more than this one. -- -- Ken Loge - http://diginoodles.com -- on getPropertyDescriptionList me list = [:] addProp list, #pMaxNum, [#comment: "Maximum Slider Value:", #format: #integer, #default: 100] addProp list, #pUseTextMember, [#comment: "Display value in text cast member?", #format: #boolean, #default: 1] addProp list, #pTextMember, [#comment: "Display value in which text cast member?", #format: #text, #default: "info"] addProp list, #pTextSpriteOffset, [#comment: "Offset for text sprite display location:", #format: #point, #default: point(-84, -10)] return list end on mouseDown me pDragging = TRUE end on mouseUp me pDragging = FALSE resetTextDisplay(me) end on mouseUpOutside me pDragging = FALSE resetTextDisplay(me) end on moveSlider me if pDragging = TRUE then pSliderSprite.locV = _mouse.mouseV - pOffY -- constrain sprite movement if pSliderSprite.locV > pYmax then pSliderSprite.locV = pYmax if pSliderSprite.locV < pYmin then pSliderSprite.locV = pYmin -- get slider value as a float between 0 and 1 floatVal = (pSliderSprite.locV - pYmax) / float(pYmin - pYmax) -- factor in number range to value and limit to set range newVal = string(integer(floatVal * float(pMaxNum))) -- set global variable to the value of the slider -- change the global variable's name here if you use more than one slider _global.sliderValue2 = newVal if pUseTextMember = TRUE then -- update text member only if value has changed if newVal <> pValueString then member(pTextMember).text = string(_global.sliderValue2) pValueString = _global.sliderValue2 end if -- move text member relative to widget if _mouse.mouseDown then sprite(pTextSprite).loc = sprite(me.spriteNum).loc + pTextSpriteOffset end if end if end if end on exitFrame me moveSlider(me) end -- move the text member back to its origin on resetTextDisplay me if pUseTextMember = TRUE then sprite(pTextSprite).loc = pTextSpriteLoc end if end