#12005/9/20 21:54:02
我用的是行为库中的音量控制,在2000中没问题,在xp中不管用。
请教大家。
语句如下:
property soundChannel -- sound channel to affect
property constraintSprite -- sprite to use to determine movement direction
-- and boundaries
property initialVolume -- starting volume of sound
property spriteNum
property mySprite
property myActiveFlag -- has slider been clicked on
property myDirection -- wich way does slider move
property myBounds -- upper and lower values for movement
property myClickOffset -- difference between mouse click and sprite loc
property pLastVol -- remembered volume setting
--SPRITE HANDLERS
on beginSprite (me)
mySprite = sprite (spriteNum)
-- set flag to indicate that sprite has not been clicked on yet
myActiveFlag = FALSE
-- get a list of the sprites containing this one
inList = me.insideSpriteList (spriteNum)
-- check to make sure the selected constraint
-- sprite hasn't been moved or deleted
if getPos(inList, constraintSprite) = 0 then
-- chosen sprite is no longer a valid constraint
-- use the stage instead
constraintSprite = 0
end if
if constraintSprite = 0 then -- stage is constraint
boundRect = (the stage).rect
-- modify rect to start at 0, 0
boundRect = offset (boundRect, -boundRect.left, -boundRect.top)
else
boundRect = sprite (constraintSprite).rect
end if
-- determine whether movement is horizontal or vertical
-- by comparing bounding rectangle width and height
boundWidth = boundRect.width
boundHeight = boundRect.height
if boundWidth > boundHeight then
-- width of bounding rect is greater than height
-- sprite will move horizontally
-- boundaries are set by using the difference between the
-- sprite's horizontal loc and sides, in combination
-- with the bounding rectangle's sides, to determine maximum
-- and minimum values for the sprite loc, so that the
-- sprite won't move out of the rectangle
myBounds = \
[#min: boundRect.left + mySprite.locH - mySprite.left, \
#max: boundRect.right + mySprite.locH - mySprite.right]
-- determine the range of sprite movement, used in volume calculations
myBounds[#range] = myBounds.max - myBounds.min
-- set the sprite direction variable
myDirection = #horizontal
else
-- height of bounding rect is greater than width
-- sprite will move vertically
-- boundaries are set by using the difference between the
-- sprite's vertical loc and the top and bottom, in combination
-- with the bounding rectangle's top and bottom, to determine maximum
-- and minimum values for the sprite loc, so that the
-- sprite won't move out of the rectangle
myBounds = \
[#min: boundRect.top + mySprite.locV - mySprite.top, \
#max: boundRect.bottom + mySprite.locV - mySprite.bottom]
-- determine the range of sprite movement
myBounds[#range] = myBounds.max - myBounds.min
-- set the sprite direction variable
myDirection = #vertical
end if
-- set the volume of the sound channel to match that
-- specified in the parameters dialog
sound (soundChannel).volume = initialVolume
pLastVol = sound (soundChannel).volume
-- determine where in the range of movement the sprite
-- needs to be for the initial volume setting
newLoc = myBounds.range * initialVolume / 255
case myDirection of
-- move the sprite from left (minimum) to right (maximum)
#horizontal: mySprite.locH = myBounds.min + newLoc
-- move the sprite from bottom (maximum) to top (minimum)
#vertical: mySprite.locV = myBounds.max - newLoc
end case
end beginSprite
-- EVENT HANDLERS
on mouseUpOutside (me)
-- when the mouse has been released outside of the sprite
-- reset the activity flag to stop tracking the cursor
myActiveFlag = FALSE
end mouseLeave
on mouseDown (me)
-- the slider thumb has been clicked on, determine where the
-- sprite's top left corner is, how far that is from the point that
-- was clicked on, and set the activity flag to track the mouse
myClickOffset = the clickLoc - sprite (spriteNum).loc
myActiveFlag = TRUE
end mouseDown
on mouseUp (me)
-- reset the mouse tracking flag when the mouse button is released
myActiveFlag = FALSE
end mouseUp
on prepareFrame (me)
if myActiveFlag then
-- sprite has been clicked on and mouse is being tracked
-- calculate new location by finding mouse loc and
-- subtracting the click offset value
case myDirection of
#horizontal:
newLoc = the mouseLoc.locH - myClickOffset.locH
#vertical:
newLoc = the mouseLoc.locV - myClickOffset.locV
end case
-- make sure new location is in within our bounds
if newLoc < myBounds.min then
-- peg the new location to the minimum
newLoc = myBounds.min
else
if newLoc > myBounds.max then
-- peg the new location to the maximum
newLoc = myBounds.max
end if
end if
-- set the sprite location
case myDirection of
#horizontal:
mySprite.locH = newLoc
#vertical:
mySprite.locV = newLoc
end case
end if
-- set volume
case myDirection of
-- horizontal sliders use the distance of the sprite
-- from the leftmost (minimum) boundary
#horizontal: offsetLoc = mySprite.locH - myBounds.min
-- vertical sliders use the distance of the sprite
-- from the bottom (maximum) boundary
#vertical: offsetLoc = myBounds.max - mySprite.locV
end case
-- change the sound channel volume to a value proportional
-- to the offset divided by the range times the maximum value
if myActiveFlag then
sound (soundChannel).volume = 255 * offSetLoc / myBounds.range
else
if sound (soundChannel).volume <> pLastVol then
-- volume value has changed due to other slider
-- need to move sprite to match current values
newLoc = myBounds.range * sound (soundChannel).volume / 255
case myDirection of
-- move the sprite from left (minimum) to right (maximum)
#horizontal: mySprite.locH = myBounds.min + newLoc
-- move the sprite from bottom (maximum) to top (minimum)
#vertical: mySprite.locV = myBounds.max - newLoc
end case
end if
end if
pLastVol = sound (soundChannel).volume
end prepareFrame
-- CUSTOM HANDLERS
on insideSpriteList (me, whichSprite)
-- creates a list of sprites containing
-- sprite (whichSprite)
spriteList = [0]
-- cycle through the sprite channels under this sprite
thisSprite = sprite (whichSprite)
repeat with i = 1 to (whichSprite - 1)
-- check to see what type of sprite it is
case sprite(i).member.type of
#animgif, #bitmap, #picture, #QuickTimeMedia, \
#digitalVideo, #shape, #field, #filmLoop, \
#flash, #text, #movie, #vectorShape:
-- check to make sure potential constraint sprite
-- is wider or taller
if ((sprite (i).left < thisSprite.left) and \
(sprite (i).right > thisSprite.right)) or \
((sprite (i).top < thisSprite.top) and \
(sprite (i).bottom > thisSprite.bottom)) then
spriteList.add(i)
end if
end case
end repeat
return spriteList
end insideSpriteList
-- BEHAVIOR DESCRIPTION BLOCK
on IsOkToAttach (me, aSpriteType, aSpriteNum)
-- can be attached to any graphic sprite
isOK = FALSE
case aSpriteType of
#graphic:
isOK = TRUE
end case
return isOK
end isOKToAttach
on getPropertyDescriptionList (me)
props = [:]
props[#soundChannel] = [ \
#comment: "要控制的声音通道:", \
#format: #integer, \
#default: 1, \
#range: [1, 2, 3, 4, 5, 6, 7, 8]]
props[#constraintSprite] = [ \
#comment: "滑动槽精灵(0 = 舞台范围):", \
#format: #integer, \
#default: 0, \
#range: me.insideSpriteList(the currentSpriteNum)]
props[#initialVolume] = [ \
#comment: "初始音量大小:", \
#format: #integer, \
#default: 255, \
#range: [#min: 0, #max: 255]]
return props
end getPropertyDescriptionList
on getBehaviorTooltip (me)
return \
"控制某个声音通道的音量大小."
end getBehaviorTooltip
on getBehaviorDescription (me)
return \
"控制声道音量大小" & RETURN & \
"该行为可以制作一个音量控制杆,以单独控制你所设定要控制的声音通道的音量大小" & RETURN & \
"将该行为拖到滑动块精灵上,滑动槽就是滑块滑动的距离." & RETURN & \
"当滑动槽的宽大于高时,滑块可以作水平滑动,向右移动滑块音量增大. " & \
"当滑动槽的宽小于高时,滑块可以作垂直滑动,向上移动滑块音量增大. " & \
"移量的值是从0~~255." & RETURN & \
"使用演员类型:" & RETURN & \
"Graphics." & RETURN & \
"参数:" & RETURN & \
"* 要控制的声音通道." & RETURN & \
"* 滑动槽精灵." & RETURN & \
"* 初始音量大小." & RETURN & \
"* 阿元翻译."
end getBehaviorDescription