主题:  滚动条代码

268

职务:普通成员
等级:1
金币:0.0
发贴:124
#12004/8/2 15:34:22
-- Scroller scriptproperty pnVisibleLines --滚动框中的可见行数
property pOnScreenField -- 视屏文字域的名字或脚色号
property pchThumb -- 滑动块的通道号
property pchScrollBar -- 滑动杆的通道号
property pTheTextString -- 滚动文字
property pCurrentTopLine -- 当前最高行号
property pStartLineOfLastFullScreen -- 上一满屏的起始行号
property pThumbTop -- 滑动杆所能到的最高偏移值(pixel计算)
property pThumbBottom -- 滑动杆所能到的最低偏移值(pixel计算)
property pThumbRange -- 滑动杆所能移动范围(pixel计算)
property pHeightPerLine -- 每一文字行的高度(pixel计算)

--滚动条对象包含以下句柄:

--用于初始化的NEW句柄
on new me, textString, targetField, visibleLines, chScrollBar, chThumb
set pTheTextString = textString
set pOnScreenField = targetField
set pnVisibleLines = visibleLines
set pchScrollBar = chScrollBar
set pchThumb = chThumb
set pThumbTop = the top of sprite pchScrollBar + (the height of sprite pchThumb / 2)
set pThumbBottom = the bottom of sprite pchScrollBar - (the height of sprite pchThumb / 2)
set pThumbRange = pThumbBottom - pThumbTop
set pStartLineOfLastFullScreen = the number of lines of pTheTextString - (pnVisibleLines - 1)
set pHeightPerLine = float(pThumbRange) / float(pStartLineOfLastFullScreen - 1)
set pCurrentTopLine = 1
mScroll(me, 0)
puppetSprite pchThumb, TRUE
return me
end birth

on mHitScrollArrow me, upOrDown --单击滚动杆的上下箭头的句柄
set chArrow = the clickOn
if upOrDown = #Up then
set scrollAmount = -1
else
set scrollAmount = 1
end if
mScroll(me, scrollAmount)
repeat while the mouseDown
mScroll(me, scrollAmount)
end repeat

end mHitScrollArrow

on mHitScrollBar me --单击滚动杆的句柄
if the mouseV > the locV of sprite pchThumb then mScroll(me, (pnVisibleLines - 1))
repeat while the stillDown AND (the bottom of sprite pchThumb < the mouseV)
mScroll(me, (pnVisibleLines - 1))
end repeatelse
mScroll(me, -1 * (pnVisibleLines - 1))
repeat while the stillDown AND (the top of sprite pchThumb > the mouseV)
mScroll(me, -1 * (pnVisibleLines - 1))
end repeat
end if
end mHitScrollBar

on mDragThumb me --拖动滚动块的句柄
repeat while the mouseDown
set newMouseV = the mouseV
if newMouseV >= pThumbBottom then
set newMouseV = pThumbBottom
else if newMouseV <= pThumbTop then
set newMouseV = pThumbTop
end if
set the locV of sprite pchThumb = newMouseV
updateStage
end repeat
set pct = float(newMouseV - pThumbTop) / float(pThumbRange)
set tempTopLine = pStartLineOfLastFullScreen * pct
set pCurrentTopLine = integer(tempTopLine + 0.5)
if pCurrentTopLine = 0 then
set pCurrentTopLine = 1
end if
mScroll(me, 0)
end mDragThumb

on mScroll me, nLines --滚动nLines行
set pCurrentTopLine = (pCurrentTopLine + nLines)
if (pCurrentTopLine < 1) then
set pCurrentTopLine = 1
end if
if pCurrentTopLine > pStartLineOfLastFullScreen then
set pCurrentTopLine = pStartLineOfLastFullScreen
end if
set the text of field pOnScreenField = line pCurrentTopLine to (pCurrentTopLine + (pnVisibleLines - 1)) of pTheTextString
set pixelOffset = integer(pHeightPerLine * float(pCurrentTopLine - 1))
set the locV of sprite pchThumb = pThumbTop + pixelOffset
updateStage
end mScroll



268

职务:普通成员
等级:1
金币:0.0
发贴:124
#22004/8/2 15:36:54
这是滚动条父脚本的代码,我网上找的,天书一样,对我这样的新手太难了,我直接拿来用,还有语法问题,那位高手帮忙调一下,谢谢!



268

职务:普通成员
等级:1
金币:0.0
发贴:124
#32004/8/2 15:57:40
特级,望高手指点,