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
Display an objects properties in Director
Cool Control Button
Rolling a Ball.
Gang Buster
Number of CD Tracks - MCI
Buddy Zip/Unzip
Ripple Button-Alphamania
Library for the control of volume in Director
Title Name MIAW
Building a Generic Card Shuffler
 

 

 

Behavior Slider-Alphamania

Added on 6/10/1999

 

Compatibilities:
D6_5 D7 D8 Mac PC Script

This item has not yet been rated

Author: MediaLab (website)

Requires Effector Set 1 Behavior Support Scripts

property button, bar, direction, min, max, percentage, range, offset, Location,Name,downMem
property msgMovie,msgSprite,msgSpriteNum,sliderMsg,defaultVal
-- a simple horizontal or vertical slider.
-- properties:
--    button; the sprite number of the slider 'button' (the thing that slides)
--    bar; the sprite number of the slider bar itself.
--    direction; #Horizaontal or #Vertical
--    min; the pixel value of the left (or bottom) end of the slider
--    max; the pixel value of the right (or top) end of the slider
--    percentage; the current percentage value represented by the slider
--    range; the number of pixels between 'min' and 'max'
--    offset; the actual pixel location along the slider
--    location; the fixed location of the slider.  This does not change, unless the actual
--    location of the slider changes.
--    the developer needs to provide a handler called "sliderIsMoving" which is called whenever the slider's value is changed.

on getPropertyDescriptionList
  
  set s=the currentSpriteNum
  if s>0 then
    set nameDef=(the name of member (the member of sprite s))
    set memDef= nameDef & "*"
    set barDef=s-1
  end if
  set pList=[:]
  addProp pList, #Name,[#comment:   "Slider Name:", ¬
                            #format:   #string, ¬
                           #default:    nameDef ]
  
  addProp pList, #DownMem,[#comment:   "Hilite Image:", ¬
                            #format:   #graphic, ¬
                           #default:    memDef ]
  
  addProp pList,#bar,[#comment:  "Range channel:",¬
                             #format: #integer,¬
                            #default: barDef]
  
  addProp pList,#direction,[#comment:"Direction:",¬
                            #format: #symbol,¬
                             #default:#Horizontal,¬
                            #range:[#Horizontal,#Vertical]]
  
  addProp pList,#defaultVal,[#comment:"Default Value (%):",¬
                            #format: #integer,¬
                             #default:1]
  
  addProp pList,#msgMovie,[#comment:"Message Movie:",¬
                            #format: #boolean,¬
                             #default:1]
  
  addProp pList,#msgSprite,[#comment:"Message Sprite:",¬
                            #format: #boolean,¬
                             #default:0]
  
  addProp pList,#msgSpriteNum,[#comment:"Sprite Number:",¬
                            #format: #integer,#default:1]
  
  addProp pList,#sliderMsg,[#comment:"Send this message:",¬
                            #format: #string,¬
                             #default:"sliderIsMoving"]
  
  return pList
end

on getBehaviorDescription
  return "Creates a slider"
end

on beginSprite me
  set sliderMsg=value("#" & sliderMsg)
  set button=the spriteNum of me
  setDirection(me)
  set offset = 0
  if defaultVal<1 then set defaultVal=1
  if defaultVal>100 then set defaultVal=100
  setSlider me, defaultVal
  return me
end

on setBar me, b
  set bar = b
  setDirection(me)
end

on setLocation me,l
  case direction of
    #Horizontal: set the locV of sprite button = l
    #Vertical: set the locH of sprite button = l
  end case
  setSlider me,percentage
end

on mouseDown me
  operate(me)
end

on operate me  
  set the member of sprite button = member downMem
  repeat while the mouseDown
    if direction=#horizontal then
      set mh = the mouseH
      if mh < min then set mh=min
      if mh > max then set mh=max
      set the locH of sprite button = mh
      set offset = mh - min
    else -- vertical
      set mv= the mouseV
      if mv > min then set mv=min
      if mv      set the locV of sprite button = mv
      set offset = min-mv
    end if
    set percentage = (offset*100) / range
    if msgMovie then sliderIsMoving(me)
    if msgSprite then sendSprite(msgSpriteNum,sliderMsg,Name,percentage)
    sendSprite(button,#step)
    updateStage
  end repeat
end

on setSlider me,p,flag
  set percentage = p
  set offset = (range*percentage) / 100
  case direction of
    #Horizontal: set the locH of sprite button = offset+min
    #Vertical: set the locV of sprite button = min-offset
  end case
  if voidP(flag) then
    if msgMovie then sliderIsMoving(me)
    if msgSprite then sendSprite(msgSpriteNum,sliderMsg,Name,percentage)
  end if
  updateStage
end

on setDirection me,d
  if not voidP(d) then set direction=d
  case direction of
    #horizontal:
      set min = the left of sprite bar
      set max = the right of sprite bar
      set range = max - min
      --set location = the locV of sprite button
    #vertical:
      set min = the bottom of sprite bar
      set max = the top of sprite bar
      set range = min - max -- it's backwards because of the screen coordinates
      --set location = the locH of sprite button
  end case
end

 


Contact

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

Send e-mail