Articles Archive
Articles Search
Director Wiki
 

A popup soundLevel utility

January 31, 1999
by Pat McClellan

Dear Multimedia Handyman,

I am trying to make a sound level popup menu on the user input. The problems, I want the changing of colour from grey to blue background whenever the cursor is place on the selection (ranging from 0 - 7). Hope you can help me...As my project's deadline is near and this is only one left unsolved...Thank you!

Nicholas

Dear Nicholas,

I'm always happy to help people learn, but please -- and other readers take note -- I can't be relied upon to provide answers on a deadline. Now, on to your question...

You can emulate the popup menu conventions with some basic behaviors (with slight modification) from the Behavior Library that ships with Director. I've done this demo so that we'll be clear on what happens. You can also download the dir file. (Mac or PC).

When you mouseDown on the Volume Button, we want it to toggle to a graphic of the button pushed down. Also the volume selection (0-7) should appear above the Volume Button. Let's deal with the toggle part first. The toggle behavior called UI Pushbutton in the Behavior Library is typical, in that when the button is pushed down, the image toggles to the downImage. However, if you roll off of the image, it reverts to the upImage. This is usually what you want, but in this case, we want the volume button to stay on the downImage while we roll off and select a volume. To make this modification, make a copy of the UI Pushbutton, and change this part:


--on mouseLeave me
--  if the button_active of me then
--    set the member of sprite (the spriteNum of me) = member the UpCM of me
--  end if 
--end
on mouseUpOutside me
  -- mouse leave will set the picture to up
  set the member of sprite (the spriteNum of me) = member the UpCM of me
  set the button_active of me = false
end

The mouseLeave handler can be commented out. But, that means we'll have to do what that handler normally does, elsewhere. Specifically, on mouseUpOutside. You can see that I've added a line to the mouseUpOutside handler.

Next, we'll deal with making the 0-7 selection appear and highlight on rollover. Create graphic cast members of each selection, 0 thru 7, as well as the highlighted versions of them. Put the graphics on stage in the correct spot. Now apply the Rollover Change Member behavior from the Behavior Library. For each sprite, select the correct member as its highlight. To make them appear and disapper, we'll create a behavior which we'll apply to the volume button. When we mouseDown on the volume button, the sprites containing the volume selections need to appear, and disappear on mouseUp or mouseUpOutside. Here's the behavior:


-- selectorToggle
-- copyright © 1999, ZZP Online, LLC
--
property pFirstSprite, pLastSprite
on getPropertyDescriptionList me
  set pdlist to [:]
  addprop pdlist, #pFirstSprite, [#comment:"First Sprite", #format:#integer, #default:0]
  addprop pdlist, #pLastSprite, [#comment:"Last Sprite", #format:#integer, #default:0]
  return pdlist
end getPropertyDescriptionList
on beginSprite me
  hideVolume me
end
on mouseDown me
  showVolume me
end
on mouseUpOutside me
  hideVolume me
end
on mouseUp me
  hideVolume me
end
on hideVolume me
  repeat with i = pFirstSprite to pLastSprite
    set spriteH = the locH of sprite i
    set the locH of sprite i to spriteH + 1000
  end repeat
end
on showVolume me
  repeat with i = pFirstSprite to pLastSprite
    set spriteH = the locH of sprite i
    set the locH of sprite i to spriteH - 1000
  end repeat
end

This behavior requires you to enter the spriteNums for the first and last of the volume selector sprites. Note that the group of volume selector sprite need to be in sequential sprite channels. On beginSprite, this behavior hides the volume selectors by moving them 1000 pixels to the right. When the mouseDown happens, the volume selector sprites are moved back into their original spots by subtracting 1000 pixels from their offstage locH.

The last thing to do is to get the soundLevel set. This is really easy. All we're going to do is let the volume selector sprites set the soundLevel when you rollover them. We'll also add a "beep" command so that the user has some feedback on what the level is.


-- setSoundLevel Behavior
-- copyright © 1999, ZZP Online, LLC
property pVolLevel
on getPropertyDescriptionList me
  set pdlist to [:]
  addprop pdlist, #pVolLevel, [#comment:"Volume Level", #format:#integer, #default:0]
  return pdlist
end getPropertyDescriptionList
on mouseEnter me
  set the soundLevel to pVolLevel
  beep
end

When you drop this behavior on each of the volume selector sprites, you'll need to enter the appropriate sound level (0-7).

Hope that helps with your program.

Patrick McClellan is Director Online's co-founder. Pat is Vice President, Managing Director for Jack Morton Worldwide, a global experiential marketing company. He is responsible for the San Francisco office, which helps major technology clients to develop marketing communications programs to reach enterprise and consumer audiences.

Copyright 1997-2024, Director Online. Article content copyright by respective authors.