property pSliderSprite -- the slider widget sprite property pXmin, pXmax -- range values for the widget property pSliderLength -- the length of the slider track property pDragging -- is the widget sprite being dragged? property pOffX -- horizontal offset between mouse click and sprite location property pVideoSprite -- video sprite to get data from property pCurVideoTime -- the current time of the video sprite property pLegacyCompatible -- make this behavior compatible with Macromedia Director MX 2004? on beginSprite me pSliderSprite = sprite(me.spritenum) -- slider track sprite is in the previous sprite channel from this one pXmin = sprite(me.spritenum - 1).left -- set slider widget range pXmax = sprite(me.spritenum - 1).right pSliderLength = pXmax - pXmin end -- VIDEO SCRUB BEHAVIOR -- -- Allows a widget sprite to control the current playback time of a video. -- It also makes the slider widget "chase" the video playback time. -- This behavior should be attached to the moveable widget. -- -- There are two parts to a slider: -- 1) The moveable slider widget. (This sprite.) -- 2) The "track" the widget slides along. (Another sprite, in a previous sprite channel.) -- -- This script looks for the track of the slider in a sprite channel -- that is one less than this one. As written, this behavior is -- designed only for horizontally oriented time scrubbing. -- -- Ken Loge - http://diginoodles.com -- on getPropertyDescriptionList me list = [:] addProp list, #pVideoSprite, [#comment: "Sprite channel of video sprite to control:", #format: #integer, #default: "1"] addProp list, #pLegacyCompatible, [#comment: "Make this behavior work with Director MX 2004:", #format: #boolean, #default: FALSE] return list end on mouseDown me pOffX = _mouse.mouseH - pSliderSprite.locH pDragging = TRUE end on mouseUp me pDragging = FALSE end on mouseUpOutside me pDragging = FALSE end on enterFrame me if pDragging = TRUE then -- scrub the video if the slider widget is moved pSliderSprite.locH = _mouse.mouseH - pOffX -- constrain widget movement if pSliderSprite.locH > pXmax then pSliderSprite.locH = pXmax if pSliderSprite.locH < pXmin then pSliderSprite.locH = pXmin -- get widget value as a float value between 0 and 1 floatVal = (pSliderSprite.locH - pXmin) / float(pXmax - pXmin) -- get the name of the video member from its sprite channel videoMember = sprite(pVideoSprite).member.name -- get the duration of the video member in milliseconds if pLegacyCompatible = TRUE then -- use ticks for Macromedia Director MX 2004 mode videoDuration = member(videoMember).duration else -- use millisecons for Adobe Director 11 and newer videoDuration = float(member(videoMember).duration / 60.0) * 1000 end if -- factor in video duration to value pCurVideoTime = integer(floatVal * float(videoDuration)) -- scrub the video time to the widget value if pLegacyCompatible = TRUE then -- Macromedia Director MX 2004 uses movieTime, which is in ticks sprite(pVideoSprite).movieTime = pCurVideoTime else -- Adobe Director 11 and newer use currentTime, which is in milliseconds sprite(pVideoSprite).currentTime = pCurVideoTime end if else -- move the widget with the playback time of the video -- get the name of the video member from its sprite channel videoMember = sprite(pVideoSprite).member.name -- get the duration of the video member in milliseconds if pLegacyCompatible = TRUE then -- use ticks for Macromedia Director MX 2004 mode videoDuration = member(videoMember).duration else -- use millisecons for Adobe Director 11 and newer videoDuration = float(member(videoMember).duration / 60.0) * 1000 end if -- compute widget movement widgetStep = float(pSliderLength / videoDuration) -- use the correct time base for control if pLegacyCompatible = TRUE then -- Macromedia Director MX 2004 uses movieTime, which is in ticks pSliderSprite.locH = integer(sprite(pVideoSprite).movieTime * widgetStep) + pSliderSprite.width / 2 else -- Adobe Director 11 and newer use currentTime, which is in milliseconds pSliderSprite.locH = integer(sprite(pVideoSprite).currentTime * widgetStep) + pSliderSprite.width / 2 end if if pSliderSprite.locH > pXmax then pSliderSprite.locH = pXmax if pSliderSprite.locH < pXmin then pSliderSprite.locH = pXmin end if end