Mark A. Boyd's

[MBlogo Animation]  mboyd.com  [MBlogo Animation]

soundPlayButton Behavior

[myDirector] [Home]

In response to a question on the macromedia.director.basics newsgroup:

"I have a toggle button set up to control a WAV file. When the user hits the Play button, it plays the sound and becomes a Stop button. How can I get the button to remember that it should be in its Stop state when the user returns to this frame?"

When dropped on a graphic sprite this behavior will allow you to choose a sound member to play (via puppetSound) and select 4 button states: Play up, Play down, Stop Up, and Stop down. You can then choose which sound channel to use.

It will "remember" the proper state the button should be in when you return to this frame.

It will also revert back to the Play button when the music stops.

Director 6.5 script. To use with D8 or higher replace all ¬ characters with \.

The Lingo:
(Syntax highlighting provided by David Mennenoh's way cool HTML-ingo utility).


-- by Mark A. Boyd
-- http://www.mboyd.com/
-- 16-May-2000 - Removed all (hopefully) remaining dot syntax
-- 13-May-2000 - placed in the public domain

property spriteNum, mySprite
property pPlayMem -- Play button member
property pPlayDownMem -- optional down state
property pStopMem -- Stop button member
property pStopDownMem -- optional down state
property pMusicMem -- sound or music to play
property pSoundChannel -- sound channel
property pPlayState -- toggle flag

on beginSprite me
  set mySprite = sprite(spriteNum)
  set pPlayState = soundBusy(pSoundChannel)
  mSwapMyMem
end

on mouseDown me
  if pPlayState then
    set the member of sprite mySprite = pPlayDownMem
  else
    set the member of sprite mySprite = pStopDownMem
  end if
end

on mouseUp me
  set pPlayState = NOT pPlayState
  if pPlayState = 1 then
    -- start playing
    puppetSound(pSoundChannel,pMusicMem)
  else
    -- stop playing
    puppetSound(pSoundChannel,pPlayState)
  end if
  mSwapMyMem
end

on mouseLeave me
  mSwapMyMem
end

on mouseUpOutSide me
  mSwapMyMem
end

on prepareFrame me
  -- swap members only if the sound has changed states
  -- ie: The music stopped
  if pPlayState <> soundBusy(pSoundChannel) then
    set pPlayState = soundBusy(pSoundChannel)
    mSwapMyMem
  end if
end

on mSwapMyMem me
  if pPlayState then
    -- music playing. Set member to stop member
    set the member of sprite mySprite = pStopMem
  else
    -- music stopped. Set member to play member
    set the member of mySprite = pPlayMem
  end if
end

on getPropertyDescriptionList me
  if the currentSpriteNum = 0 then exit
  set myMem = the member of sprite (the currentSpriteNum)
  set theNum = (the memberNum of myMem) + 1
  set theLib = the castLibNum of member myMem
  set defPlayDown = member theNum of castLib theLib
  set theNum = theNum + 1
  set defStopMem = member theNum of castLib theLib
  set theNum = theNum + 1
  set defStopDown = member theNum of castLib theLib
  set pList = [:]
  
  addProp(pList,#pPlayMem,[¬
  #comment:"Play button:"
  #format:#bitmap,¬
  #default:myMem])
  
  addProp(pList,#pPlayDownMem,[¬
  #comment:"Play button down:"
  #format:#bitmap,¬
  #default:defPlayDown])
  
  addProp(pList,#pStopMem,[¬
  #comment:"Stop button:"
  #format:#bitmap,¬
  #default:member(defStopMem)])
  
  addProp(pList,#pStopDownMem,[¬
  #comment:"Stop button down:"
  #format:#bitmap,¬
  #default:member(defStopDown)])
  
  addProp(pList,#pMusicMem,[¬
  #comment:"Sound to play:"
  #format:#sound,¬
  #default:1])
  
  addProp(pList,#pSoundChannel,[¬
  #comment:"Sound Channel:"
  #format:#integer,¬
  #default:1,¬
  #range:[#min:1,#max:8]])
  
  return pList
end

on getBehaviorDescription me
  return "When dropped on a graphic sprite this behavior will allow you to choose a sound member to play (via puppetSound) and select 4 button states: Play up, Play down, Stop Up, and Stop down. You can then choose which sound channel to use." &return &return &"It will " &quote &"remember" &quote &&"the proper state the button should be in when you return to this frame." &return &return &"It will also revert back to the Play button when the music stops."
end


Home