<text>
The basic text display element.

JavaScript: lz.text
extends <view> » <node> » lz.Eventable »

This class is used for non-editable text fields (as opposed to <inputtext>). A text field can be initalized with text content at compile time.

<canvas height="30">
   <text>Hello world!</text>
 </canvas>
edit

Text objects can also display text that is computed at runtime.

<canvas height="30">
       <class name="clickClock" extends="text">
         <attribute name="dayTable" value="["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"]"/>
         <handler name="onclick">
           var now = new Date;
           this.format("You clicked me at %02d:%02d:%02d on %s",
                       now.getHours(),
                       now.getMinutes(),
                       now.getSeconds(),
                       dayTable[now.getDay()]);
         </handler>
       </class>
       <clickClock>
         Click Me!
       </clickClock>
     </canvas>
edit

Note that certain attributes on text objects, such as opacity and rotation, only work on embedded fonts. They do not work on client fonts (also called platform fonts, native fonts, platform fonts, etc). See the Developer's Guide for details.

See Also:

  • The Text Views chapter of the Developer's Guide for a discussion of how to include and manipulate text
  • The canvas.maxtextheight and canvas.maxtextwidth attributes

Attributes

Name Type (tag) Type (js) Default Category
letterspacing number Number   read/write
  letter-spacing for this text
maxlength numberExpression Number   read/write
  Maximum number of characters allowed in this field
maxlines Number Number   readonly
  The number of lines that will fit in the current height
multiline boolean Boolean "false" initialize-only
  If true, the lines of text are wrapped to fit within the text width. (The name multiline is a misnomer. Unwrapped text can be multiple lines if it contains a <br /> or <p> element, or a line break within a <pre> element. This attribute defaults to true if width and height are explicitly specified. If you set multiline=true, you probably want to explicitly a width for the text also; if multiline=true and you do not specify a width, the system will pick an arbitrary width (100 pixels at the moment). When multiline=true, the text is automatially re-wrapped whenever the content is modified by calls to setText, or whenever the width of the text view is modified.
pattern string String   read/write
  regexp describing set of characters allowed in this field Restrict the characters that can be entered to a pattern specified by a regular expression. Currently only the expression [ ]* enclosing a set of characters or character ranges, preceded by an optional "^", is supported. examples: [0-9]* , [a-zA-Z0-9]*, [^0-9]*
resize booleanLiteral Boolean   read/write
  If true, the width of the text field will be recomputed each time text is changed, so that the text view is exactly as wide as the width of the widest line. Defaults to true.
selectable booleanLiteral Boolean   read/write
  If true, the text is selectable
text string String   read/write
  The text to display in this text field. If set to a value that is not a string, the value will first be converted to a string as if by String(value). To display nothing, set the value to the empty string "".
textalign string String   read/write
  text-align for this text
textdecoration string String   read/write
  text-decoration for this text
textindent number Number   read/write
  text-indent for this text
xscroll Number Number   read/write
  The x scroll position of the textfield.
yscroll Number Number   read/write
  The y scroll position of the textfield.

Methods

addFormat()
text.addFormat(control : string, args : [*]);
Appending version of formatted output. Formats its arguments using LzFormatter.formatToString() and adds the result to the text of the view.
Parameter Name Type Description
control string A control string where % indicates the conversion of the corresponding argument
args [*] arguments to be formatted according to the control string

addText()
text.addText(t : String);
Appends the string to the current text in the textfield.
Parameter Name Type Description
t String The string to add

clearText()
text.clearText();
Clears the text field (by setting its text to the empty string)

escapeText()
text.escapeText(ts : String);
Returns an escaped version of the string if called with no args. If called with a string argument, returns an escaped version of that string (escaped here means markup-escaped, not http escaped.)
Parameter Name Type Description
ts String text string to escape

format()
text.format(control : string, args : [*]);
Formatted output. Formats its arguments using LzFormatter.formatToString() and sets the text of the view to the result.
Parameter Name Type Description
control string A control string where % indicates the conversion of the corresponding argument
args [*] arguments to be formatted according to the control string

getAntiAliasType()
text.getAntiAliasType();
Gets the kind of antialiasing set on this text object
Returns Type Description
  String The current setting for text antialiasing

getGridFit()
text.getGridFit();
Gets the kind of grid fitting set on this text object
Returns Type Description
  String The current setting for grid fitting

getSelectionPosition()
text.getSelectionPosition();
Returns the position of the text cursor within this object. If the text cursor is not inside this object, then the method returns -1.
Returns Type Description
  Number The position of the text cursor within this textfield, 0 based. If the text cursor is not in the textfield, this method returns -1.

getSelectionSize()
text.getSelectionSize();
Returns the length of the text selection in within this object. If the text cursor is not inside this object, then the method returns -1.
Returns Type Description
  Number The length of the text selection within this textfield. If the text cursor is not in the textfield, this method returns -1.

getSharpness()
text.getSharpness();
Gets the sharpness rendering property of this text object
Returns Type Description
  Number The current sharpness rendering

getText()
text.getText();
Returns the string represented in the text field
Returns Type Description
  String The string in the text field

getTextHeight()
text.getTextHeight();
Calculates the current height of the text held by the text field.

getTextWidth()
text.getTextWidth();
Calculates the current width of the text held by the text field.

getThickness()
text.getThickness();
Gets the thickness rendering property of this text object
Returns Type Description
  Number The current thickness rendering

makeTextLink()
text.makeTextLink(str : String, value : String);
Return a string which can be used to insert a hyperlink in a text field.
Parameter Name Type Description
str String The text displayed in the hyperlink.
value String The value returned when the link is clicked.

setAntiAliasType()
text.setAntiAliasType(aliasType : String);
[Caution] This method is deprecated
Use setAttribute('antiAliasType', ...) instead.
Sets what type of antialiasing the text field should use. Only works in swf8 and higher.
Parameter Name Type Description
aliasType String "normal" or "advanced"

setGridFit()
text.setGridFit(gridFit : String);
[Caution] This method is deprecated
Use setAttribute('gridFit', ...) instead.
Sets what type of grid fitting the text field should use. Only works in swf8 and higher.
Parameter Name Type Description
gridFit String "none", "pixel", or "subpixel"

setHScroll()
text.setHScroll(s : Number);
Sets the horizontal scroll position
Parameter Name Type Description
s Number horizontal scroll position

setMultiline()
text.setMultiline(ml : Boolean);
[Caution] This method is deprecated
Use setAttribute('multiline', ...) instead.
Sets whether or not the textfield wraps. If false, only a single line of text will appear and extra lines will be trucated if the text is set with multiple lines.
Parameter Name Type Description
ml Boolean true if the text field should allow multiple lines

setResize()
text.setResize(val : Boolean);
[Caution] This method is deprecated
Use setAttribute('resize', ...) instead.
setResize set behavior of text field width when new text is added. LzText only (cannot be used with LzInputText).
Parameter Name Type Description
val Boolean if true, the textfield will recompute it's width after setText() is called

setScroll()
text.setScroll(h : Number);
Sets the vertical scroll position
Parameter Name Type Description
h Number scroll position

setSelectable()
text.setSelectable(isSel : Boolean);
[Caution] This method is deprecated
Use setAttribute('selectable', ...) instead.
Sets the selectability (with Ibeam cursor) of the text field
Parameter Name Type Description
isSel Boolean true if the text may be selected by the user

setSelection()
text.setSelection(start : Number, end : Number);
Positions the text selection within the text field. If this object does not already have the focus, this has the ancillary effect of giving it the focus.
Parameter Name Type Description
start Number The beginning of the text selection, or the position for the text cursor if no end is given. The index is 0 based.
end Number The end of the text selection. Optional. If not given, then the text cursor is positioned at the start point, but no text is selected.

setSharpness()
text.setSharpness(sharpness : Number);
[Caution] This method is deprecated
Use setAttribute('sharpness', ...) instead.
Sets the sharpness for the text rendering Only works in swf8 and higher.
Parameter Name Type Description
sharpness Number -400 to 400

setText()
text.setText(t : String);
[Caution] This method is deprecated
Use setAttribute('text', ...) instead.
Sets the text of the field to display
Parameter Name Type Description
t String the string to which to set the text

setThickness()
text.setThickness(thickness : Number);
[Caution] This method is deprecated
Use setAttribute('thickness', ...) instead.
Sets the thickness for the text rendering Only works in swf8 and higher.
Parameter Name Type Description
thickness Number -200 to 200

setXScroll()
text.setXScroll(n : Number);
[Caution] This method is deprecated
Use setAttribute('xscroll', ...) instead.
Set the x scroll position of the textfield.
Parameter Name Type Description
n Number set the left edge of the textfield to offset n pixels (n is always < 0)

setYScroll()
text.setYScroll(n : Number);
[Caution] This method is deprecated
Use setAttribute('yscroll', ...) instead.
Set the y scroll position of the textfield.
Parameter Name Type Description
n Number set the top line of the textfield to offset n pixels vertically (n is always < 0)

Methods inherited from lz.Eventable

destroy, setAttribute

Events

Name Description
onhscroll  
onmaxhscroll  
onmaxlength  
onmaxscroll  
onpattern  
onscroll  
ontext Sent whenever the text in the field changes.
ontextlink Sent when a clickable HTML link in the text field is clicked. Event data is a string with the link value.

Events inherited from <node>

onconstruct, ondata, oninit

Events inherited from lz.Eventable

ondestroy