----------------------------------------------------------------------------- -- Plays a sound and stops or fades playback if a sound is already playing. - -- Ken Loge - http://diginoodles.com - ----------------------------------------------------------------------------- property pPlayStatus -- is the sound playing, or not? property pSoundFadeDuration -- number of milliseconds to fade sound property pFadeSound -- fade the sound out = TRUE, or just stop = FALSE property pSoundMember property pSoundChannel property pSoundVolume on beginSprite pPlayStatus = FALSE end on getPropertyDescriptionList me list = [:] addProp list, #pSoundMember, [#comment: "Sound cast member to play:", #format: #sound, #default: ""] addProp list, #pSoundChannel, [#comment: "Sound Channel:", #format: #integer, #default: 1, #range: [#min: 1, #max: 8]] addProp list, #pSoundVolume, [#comment: "Sound Volume:", #format: #integer, #default: 255, #range: [#min: 0, #max: 255]] addProp list, #pSoundFadeDuration, [#comment: "Sound fade duration:", #format: #integer, #default: "500"] addProp list, #pFadeSound, [#comment: "Fade the sound, if it's already playing?", #format: #boolean, #default: TRUE] return list end -- toggle sound playback on mouseUp me if pPlayStatus = FALSE then sound(pSoundChannel).play(member(pSoundMember)) pPlayStatus = TRUE else -- fade out the sound if pFadeSound = TRUE then sound(pSoundChannel).fadeOut(pSoundFadeDuration) pPlayStatus = FALSE else -- stop the sound, with no fade sound(pSoundChannel).stop() pPlayStatus = FALSE end if end if end