- Flash 5 offered very little control over text fields
- could not be created dynamically at runtime
- could only be scrolled vertically
- could not be resized
- could not be formatted
- Flash MX introduces the TextField class for full run-time control over text.
- Text field instances can be created at author-time with the Text tool. Use the new "instance name" box in the Property inspector.
- Or, the MovieClip.createTextField() method creates a new text field instance at run-time.
// Create a text field. Params are:
// instanceName, depth, x, y, width, height
this.createTextField("output", 1, 0, 0, 200, 40);
// Assign it some text.
output.text = "what's up?"
// Add a border.
output.border = true;
// Add a background.
output.background = true;
// Make the border red.
output.borderColor = 0xFF0000;
// Make the background gray.
output.backgroundColor = 0xCCCCCC;
// Make the border fit the text automatically.
output.autoSize = true;
// Turn on HTML display
output.html = true;
// Add some HTML source for display.
output.htmlText = "wow, <B>bold!</B>";
// Stop the user from selecting the text.
output.selectable = false;
// Make the text red.
output.textColor = 0xFF0000;
// Check the new HTML source, which reflects the text color!
trace(output.htmlText);
// Displays:
// <P ALIGN="LEFT"><FONT FACE="Times New Roman"
// SIZE="12" COLOR="#FF0000">wow, <B>bold!</B></FONT></P>
// Allow user input.
output.type = "input";
output.selectable = true;
// Move the field right a bit each frame.
this.onEnterFrame = function () {
output._x += 3;
}
// Show's over...
output.removeTextField();
- Other tools not demonstrated above:
_alpha
Opacity percentage: 0 is transparent; 100 is opaque.
bottomScroll
The 1-based index of the text field's lowest visible line.
embedFonts
Render text using fonts exported with the movie.
_height
Height of the text field's bounding box, in pixels.
hscroll
Text's horizontal scroll position, in pixels.
length
The number of characters in the text field.
maxChars
Limits the allowed length of user input.
maxhscroll
The farthest position text can be scrolled to the left.
maxscroll
The last legal top line of a text field.
multiline
Boolean; enables or disables multiple line user input.
_name
The instance name of the TextField object.
_parent
A reference to the movie clip in which the field resides.
password
Obscure characters displayed in the field.
restrict
Limit text entry to a series of characters.
_rotation
Rotation, in degrees, of the text field (requires embedded font).
scroll
The current top line displayed in the text field.
tabEnabled
Boolean; includes or excludes the text field from the current tab order.
tabIndex
Specifies the text field's index in the custom tab order.
_target
The target path of the text field, in slash syntax.
textHeight
Pixel height of all the text in the text field.
textWidth
Pixel width of the longest line in the text field.
_url
The network address of the movie clip that contains the field.
variable
Associates a variable with the text property.
_visible
Whether the text field is shown or hidden.
_width
Width of the text field's bounding box, in pixels.
wordWrap
Enable automatic line breaking for long lines.
_xmouse
Horizontal location of mouse pointer, relative to the text field.
_xscale
Width of a text field, as a percentage.
_y
Vertical location of the text field, in pixels.
_ymouse
Vertical location of mouse pointer, relative to the text field.
_yscale
Height of a text field, as a percentage.
addListener( )
Registers an object to receive onChanged() and onScroller() events.
getDepth( )
Returns the position of the text field in the movie stack.
getNewTextFormat( )
Retrieves the default TextFormat object for the text field.
getTextFormat( )
Retrieves a TextFormat object for specified characters.
removeListener( )
Cancels event notices for the specified listener.
replaceSel()
Replace selected text (without disturbing formatting).
setNewTextFormat()
Sets the default formatting for the text field.
setTextFormat()
Sets the formatting of specified characters.
onChanged( )
Callback/listener invoked when user input is detected.
onKillFocus( )
Callback invoked when the field loses focus.
onScroller()
Callback/listener invoked when any scroll property changes.
onSetFocus()
Callback invoked when the field gains focus.
-
Some text field demos (these are done but not polished. look for the finals in the asdg code depot):