Contents
Articles
Behaviors
Books
Director News
Director Web Sites
FAQ
Games
Mailing Lists
News Groups
Project Examples
Reviews
Software
Tools
Useful Web Sites
Utilities
Xtras

Don't miss these
Vdig Xtra for Windows by Abstract Plane
Set DirectToStage of a Animated Gif Sprite
Open Acrobat File
Manipulating Date and Time using Lingo
Find CD Drives letter quikly
Vector Shape - Create Polygon
Set Reveal Method-Alphamania
Dual Button With Rollover Effect
Cross Platform Projects
Lingo Library
 

 

 

Behavior Volume Control-Slider

Added on 10/2/2000

 

Compatibilities:
behavior D7 D8 PC

Required Xtras:
Buddy API

This item has not yet been rated

Author: MediaMacros (website)

This behavior will controll a volume slider with the parameters you set

--You must have a slider and a quickdraw line as a slide bar.  You may also choose to include both an up arrow and down arrow and each piece can have a regular, rollover, and a click state.  Simply drop this behavior on all 4 elements and choose which part it is frm the popup box.  Also, you need to select whether it is a vertical (V) or horizontal (H) slider.

property whatWidget, soundNotch, sliderSprite, defaultmember, rolloverMember, clickMember, spriteNum, alreadySet, inc, hV, whatVolume

on getPropertyDescriptionList me
  thisSprite = the currentSpriteNum
  return [#whatWidget : [#format : #symbol, #comment : "Which piece is this?", #range : [#Slider, #SlideBar, #VolUp, #VolDown], #default : #Slider], #soundNotch : [#format : #integer, #comment : "Number of sound notches:", #default : 10, #range : [#min : 5, #max : 25]], #rolloverMember : [#format : #member, #comment : "Rollover member (for slider and buttons.)", #default : (sprite thisSprite).member], #clickMember : [#format : #member, #comment : "Click member (for slider and buttons.)", #default : (sprite thisSprite).member], #hV : [#format : #symbol, #comment : "Slider in the H or the V?(Controlled by the sliderBar)", #default : #V, #range : [#H, #V]], #whatVolume : [#format:#string, #comment : "What sound device?", #default : "Master", #range : ["Master", "CD", "Wave", "Midi", "Synth"]]]  
end

on mouseDown me
  (sprite spriteNum).member = clickMember
  if whatWidget = #Slider then
    trackSlider()
  end if  
end

on mouseUp me
  (sprite spriteNum).member = defaultMember
  if whatWidget = #VolUp or whatWidget = #volDown then
    inc = float((sprite sliderSprite).member.height) / (sprite sliderSprite).soundNotch
    vol = 0
    if (sprite sliderSprite).hV = #H then
     case whatWidget of
        #volUp : vol = -1
        #volDown : vol = 1        
      end case  
    else      
      case whatWidget of
        #volUp : vol = 1
        #volDown : vol = -1        
      end case
    end if    
    sendAllSprites(#adjVol, vol)
  end if
end

on mouseEnter me
  (sprite spriteNum).member = rolloverMember
end

on mouseLeave me
  (sprite spriteNum).member = defaultMember
end

on beginSprite me
  alreadySet = false
  defaultMember = (sprite spriteNum).member
end

on prepareFrame me
  if alreadySet = false then
    if whatWidget = #slideBar then
      sendAllSprites(#iAmSlider, the spriteNum of me)
      sendSprite(2,#iAmSlider, the spriteNum of me)
      sendAllSprites(#SetInVol, spriteNum)
    end if      
    alreadySet = true
  end if
end


on setInVol me, whatSprite
  if whatWidget = #slider then
    if (sprite whatSprite).hV = #h then        
      inc = float((sprite whatSprite).member.width) / (sprite whatSprite).soundNotch
      howFar =(float(baGetVolume(whatVolume)) /100) *(sprite whatSprite).soundNotch
      (sprite spriteNum).locH = (sprite whatSprite).right - (integer(howFar) * inc)  
    else
      inc = float((sprite whatSprite).member.height) / (sprite whatSprite).soundNotch
      howFar =(float(baGetVolume(whatVolume)) /100) *(sprite whatSprite).soundNotch
      (sprite spriteNum).locV = (sprite whatSprite).bottom-(integer(howFar) * inc)    
    end if
  end if
end

on adJVol me, theVolume
  if whatWidget = #Slider then
    if (sprite sliderSprite).hV = #H then
      inc = float((sprite sliderSprite).member.width) / (sprite sliderSprite).soundNotch
      howFar = (float((sprite sliderSprite).right) - (sprite spriteNum).locH) / inc    
      newLevel = howFar + theVolume
      if newLevel < 0 then newLevel = 0
      if newLevel > (sprite sliderSprite).soundNotch then newLevel = (sprite sliderSprite).soundNotch
      baSetVolume( whatVolume , 100 -( integer((newLevel/(sprite sliderSprite).soundNotch ) * 100)))
      (sprite spriteNum).locH = (sprite sliderSprite).right - integer(newLevel) * inc)
    else
      inc = float((sprite sliderSprite).member.height) / (sprite sliderSprite).soundNotch
      howFar = (float((sprite sliderSprite).bottom) - (sprite spriteNum).locV) / inc
      newLevel = howFar + theVolume      
      if newLevel < 0 then newLevel = 0
      if newLevel > (sprite sliderSprite).soundNotch then newLevel = (sprite sliderSprite).soundNotch
      baSetVolume( whatVolume ,  integer((newLevel/(sprite sliderSprite).soundNotch ) * 100))
      (sprite spriteNum).locV = (sprite sliderSprite).bottom-(integer(newLevel) * inc)
    end if
  end if
end

on iAmSlider me, whatSprite
  (sprite spriteNum).sliderSprite = whatSprite
end

on trackSlider me
  if (sprite sliderSprite).hV = #H then
    pos = (sprite spriteNum).locH - the mouseH
    repeat while the stillDown
      (sprite spriteNum).locH = constrainH(sliderSprite , the mouseH + pos)
      updateStage
    end repeat
    inc = float((sprite sliderSprite).member.width) / (sprite sliderSprite).soundNotch
    howFar = (float((sprite sliderSprite).right) -float(constrainH(sliderSprite, (sprite spriteNum).locH))) / inc
    (sprite SpriteNum).locH = (sprite sliderSprite).right-(integer(howFar) * inc)
    baSetVolume( whatVolume ,  100 -(integer((howFar/(sprite sliderSprite).soundNotch ) * 100)))    
  else
    pos = (sprite spriteNum).locV - the mouseV
    repeat while the stillDown
      (sprite spriteNum).locV = constrainV(sliderSprite , the mouseV + pos)
      updateStage
    end repeat
    inc = float((sprite sliderSprite).member.height) / (sprite sliderSprite).soundNotch
    howFar = (float((sprite sliderSprite).bottom) - float(constrainV(sliderSprite, (sprite spriteNum).locV))) / inc
    (sprite SpriteNum).locV = (sprite sliderSprite).bottom-(integer(howFar) * inc)
    baSetVolume( whatVolume ,  integer((howFar/(sprite sliderSprite).soundNotch ) * 100))  
  end if    
end

on getBehaviorDescription me
  describe = "This behavior will controll a volume slider with the parameters you set.  You must have a slider and a quickdraw line as a slide bar.  You may also choose to include both an up arrow and down arrow and each piece can have a regular, rollover, and a click state.  Simply drop this behavior on all 4 elements and choose which part it is frm the popup box.  Also, you need to select whether it is a vertical (V) or horizontal (H) slider."
  return describe
end

 


Contact

MMI
36 South Court Sq
Suite 300
Newnan, GA 30263
USA

Send e-mail