Some of you might have noticed I've been discussing behavior
communication with Noelle, and she asked after an example of a relay
behavior.
So here it is. This is another take on the volume button behavior for
QuickTime audio. There are three behaviors here. One is attached to
the volume button; one is attached to the target QuikckTime audio
sprite(s); the third is a framescript behavior and goes into channel
0. This third behavior is the intermediary that prevents direct
communication amongst behaviors and thus forestalls script error
occurrences.
As you can see this is relatively intricate, but it's got the
distinct advantage of being pretty flexible. You can actually have as
many QT sprites as you want in a frame, and you can change their
channel numbers at will, and as long as the settings for the
behaviors in the PI are correct, everything should work in a
completely error-free way.
All you have to do once these behaviors are made is attach the QT one
to your QT sprites, and name each one however you want to; then
attach the volume one to the volume buttons, specifying the name of
the QT sprite whose volume is to be adjusted (this would be the name
you already gave to the QT sprite). Then put the channel 0 script
into the frame script channel, hit play, and off you go.
-- For the volume buttons
PROPERTY pyMyDirection
PROPERTY psTargetName
on beginSprite me
me.InitializeMyProps()
END beginSprite
on mouseUp me
if psTargetName = "no_sprite" then
put "No QT sprite has been set for behavior" && (me.spriteNum)
exit
end if
sendSprite ( 0, #AdjustVolume, pyMyDirection, psTargetName )
END mouseUp
on InitializeMyProps me
if voidP ( pyMyDirection) then
pyMyDirection = #down
end if
if voidP ( psTargetName ) then
psTargetName = "no_sprite"
end if
END InitializeMyProps
on getPropertyDescriptionList me
lProps = [:]
lProps.addProp( #psTargetName, [#default: "name", #format: #string,\
#comment: "Name of target sprite?"] )
lProps.addProp( #pyMyDirection, [#default: #down, #format: #symbol,\
#comment: "Adjust sound down or up?" #range: \
[#down, #up] ] )
return lProps
END getPropertyDescriptionList
-- For the QuickTime sprites
PROPERTY psMyName
on beginSprite me
me.InitializeMyProps()
END beginSprite
on InitializeMyProps me
if voidP ( psMyName ) then
psMyName = "no_sprite_" & (me.spriteNum)
end if
END InitializeMyProps
on ReturnInfo me
return psMyName && (me.spriteNum)
END ReturnInfo
on AdjustQTVolume me, nIncrement
if sprite(me.spriteNum).member.type <> #quickTime then
put "Sprite" && (me.spriteNum) && "is not a QuickTime sprite."
exit
end if
sprite(me.spriteNum).volume = \
sprite(me.spriteNum).volume + nIncrement
END AdjustQTVolume
on getPropertyDescriptionList me
lProps = [:]
lProps.addProp( #psMyName, [#default: "name", #format: #string,\
#comment: "Name of this sprite?"] )
return lProps
END getPropertyDescriptionList
-- For the channel 0 script
PROPERTY plQTSpriteList
on beginSprite me
me.InitializeMyProps()
END beginSprite
on exitFrame me
go the frame
END exitFrame
on InitializeMyProps me
plQTSpriteList = [:]
nAllSprites = the lastChannel
repeat with nChannel = 1 to nAll
sReturn = sendSprite ( nChannel, #ReturnInfo )
if voidP ( sReturn ) then
next repeat
else
nAllWords = the number of words in sReturn
nSpriteNum = value ( sReturn.word[nAllWords] )
sSpriteName = sReturn.word[1..(nAllWords - 1 )]
if sSpriteName <> "no_sprite_" & nSpriteNum then
plQTSpriteList.addProp ( sSpriteName, nSpriteNum )
end if
end if
end repeat
END InitializeMyProps
on AdjustVolume me, yDirection, sTarget
nSprite = plQTSpriteList[sTarget]
if voidP ( nSprite ) then
put "Sprite" && sTarget && "is not registered as a QT sprite."
exit
end if
if yDirection = #up then
nAdjustIncrement = 1
else
nAdjustIncrement = -1
end if
sendSprite ( nSprite, #AdjustQTVolume, nAdjustIncrement )
END AdjustVolume
--
Warren Ockrassa | http://www.nightwares.com/
Director help | Free files | Sample chapters | Freelance | Consulting
Author | Director 8.5 Shockwave Studio: A Beginner's Guide
Published by Osborne/McGraw-Hill
http://www.osborne.com/indexes/beginners_guides.shtml
[To remove yourself from this list, or to change to digest mode, go to
http://www.penworks.com/lingo-l.cgi To post messages to the list, email
[EMAIL PROTECTED] (Problems, email [EMAIL PROTECTED]). Lingo-L is for
learning and helping with programming Lingo. Thanks!]