text box
The effect is as follows:
The code that wrote this effect today
Used in the diary of the homepage.
Feel the previous use of scroll objects to control the text box, rolling up more blunt
Where drag is the scroll bar name
Block is a text box
B_up,b_down for up and down scrolling buttons
The main method is to use block to always follow the drag position change and scroll
The B_up,b_down and the mouse wheel are directly controlling the position of the drag, thereby indirectly controlling the scrolling of the text box
Jtl
http://www.hartech.cn
e-mail:jtl.zheng@gmail.com//initialization function Var () {////The gap between the scroll bar and the up and down button Space = 31; The scrolling speed of the Up-down button updown_speed = 5; The scrolling range of the text box Block_range = block._height-mark._height; The initial position of the text box Block_origin = block._y; The scrolling range of the scroll bar drag_range = B_down._y-b_up._y-2*space; The initial position of the scroll bar drag_origin = B_up._y+space; Initializes the scroll bar position drag._y = Drag_origin; Rolling buffer coefficient k =. 1; Var (); Block is a text box that always follows the scroll bar (drag) Change block.onenterframe = function () {//pos is the text box destination pos = block_o rigin-(Drag._y-drag_origin) *block_range/drag_range; Buffer effect This._y + = (pos-this._y) *k; }; drag.onpress = function () {This.startdrag (False, this._x, Drag_origin, this._x, (Drag_origin+drag_range)); }; Drag.onreLease = function () {This.stopdrag (); }; Up_down button b_up.onpress = function () {onenterframe = function () {if (Drag._y<=drag _origin) {drag._y = Drag_origin; else {drag._y-= updown_speed; } }; }; B_up.onrelease = function () {onenterframe = null; }; b_down.onpress = function () {onenterframe = function () {if (Drag._y>=drag_origin+drag_range) { drag._y = Drag_origin+drag_range; else {drag._y + = Updown_speed; } }; }; B_down.onrelease = function () {onenterframe = null; }; Listens for mouse wheel MouseListener = new Object (); Mouselistener.onmousewheel = function (Delta) {if (delta>0) {drag._y-= updown_speed*2; } if (delta<0) {drag._y + = updown_speed*2; } if (drag._y<=drag_origin) {drag._y = Drag_origin; } if (drag._y>=drag_origin+drag_range) {drag._y = Drag_origin+drag_range; } }; Mouse.addlistener (MouseListener);
Create a text box code
Loadvariables ("Text/diary.txt", this); Mytextformat = new TextFormat (); Mytextformat.font = "Song Body"; Mytextformat.size =; mytextformat.leading = 3; Createtextfield ("Test_txt", 0, 0, 210, ten); Test_txt.multiline = true; Test_txt.wordwrap = true; Test_txt.autosize = true; Test_txt.html = true; Test_txt.htmltext = text; Test_txt.settextformat (Mytextformat); Test_txt.type = "Static"; Demo Address: //http://www.hartech.cn/blog/blogview.asp?logID=45