property pSliderSprite -- the slider widget sprite property pXmin, pXmax -- movement limit values for the widget property pDragging -- is the widget sprite being dragged? property pOffX -- horizontal 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 X constraints for range of movement halfWidgetWidth = pSliderSprite.width / 2 pXmin = spLine.left + halfWidgetWidth pXmax = spLine.right - halfWidgetWidth end -- X 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.sliderValue1 -- -- 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(-44, -40)] 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 -- move the slider widget on moveSlider me if pDragging = TRUE then pSliderSprite.locH = _mouse.mouseH - pOffX -- constrain sprite movement if pSliderSprite.locH > pXmax then pSliderSprite.locH = pXmax if pSliderSprite.locH < pXmin then pSliderSprite.locH = pXmin -- get slider value as a float between 0 and 1 floatVal = (pSliderSprite.locH - pXmin) / float(pXmax - pXmin) -- 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.sliderValue1 = newVal if pUseTextMember = TRUE then -- update text member only if value has changed if newVal <> pValueString then member(pTextMember).text = string(_global.sliderValue1) pValueString = _global.sliderValue1 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