
TextField.textWidth Property
This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
876
|
ActionScript Language Reference
Example
The following simplified scrollbar code scales a scrollbar handle in proportion to the
amount of overflow in a text field. Every time the field is scrolled, the code checks the ratio
of
_height to textHeight to determine the scale of the handle. It positions the handle based
on the
scroll and maxscroll properties. To try the code, first make two rectangular movie
clips named
scrollbg and scrollhandle.
// Create a multiline text field
this.createTextField("theField_txt", 1, 0, 0, 150, 40);
theField_txt.border = true;
theField_txt.text = "Line one \nLine two \nLine three \nLine four";
// Allow user input on multiple lines
theField_txt.type = "input";
theField_txt.multiline = true;
// Size the scrollbar background
scrollbg._width = 20;
scrollbg._height = theField_txt._height;
// Position the scrollbar background
scrollbg._x = theField_txt._x + theField_txt._width;
scrollbg._y = theField_txt._y;
// Size and position the scrollbar handle whenever the field is scrolled
theField_txt.onScroller = function () {
// Size the scrollbar handle
scrollhandle._width = 20;
scrollhandle._height = theField_txt._height
* (theField_txt._height / theField_txt.textHeight);
// Position the scrollbar handle
scrollhandle._x = theField_txt._x + theField_txt._width; ...