LTextField Class
Creates a new LTextField instance. After you create the LTextField instance, call the addChild() or addChildAt() method of the parent LSprite object to add the LTextField instance to the display list. The methods of the LTextField class let you set, select, and manipulate text in a dynamic or input text field that you create during authoring or at runtime.
Constructor
LTextField
()
public
Example:
var theTextField = new LTextField();
theTextField.setType(LTextFieldType.INPUT);
theTextField.x = 10;
theTextField.y = 10;
addChild(theTextField);
Item Index
Methods
Properties
Methods
addEventListener
-
type
-
listener
Registers an event listener object with an LEventDispatcher object so that the listener receives notification of an event. You can register event listeners on all nodes in the display list for a specific type of event, phase, and priority.
After you successfully register an event listener, you cannot change its priority through additional calls to addEventListener(). To change a listener's priority, you must first call removeListener(). Then you can register the listener again with the new priority level.
If you no longer need an event listener, remove it by calling removeEventListener(), or memory problems could result.
Parameters:
-
type
StringThe type of event.
-
listener
FunctionThe listener function that processes the event.
callParent
-
functionName
-
arguments
call the method of parent。
Parameters:
-
functionName
Stringfunction's name
-
arguments
ArrayFixed value : arguments
Example:
function funA(){
LExtends(this,LObject,[]);
}
funA.prototype.myName = function(){
return "AAA";
}
function funB(){
LExtends(this,funA,[]);
}
funB.prototype.myName = function(){
return "BBB";
}
function funC(){
LExtends(this,funA,[]);
}
funC.prototype.myName = function(){
return this.callParent("myName",arguments);
}
LInit(1000/50,"legend",800,150,main);
function main(){
LGlobal.setDebug(true);
var objB = new funB();
trace(objB.myName());//BBB
var objC = new funC();
trace(objC.myName());//AAA
}
clearShape
()
public
Frees memory that is used.
clone
()
LTextField
public
Returns a new LTextField object that is a clone of the original instance with an exact copy of the object.
Returns:
A new LTextField object that is identical to the original.
Example:
var circle1 = new LSprite();
circle1.graphics.drawRect(1,"#000000",[0,0,100,100],true,"#000000");
var circle2 = circle1.clone();
circle2.y = 120;
addChild(circle1);
addChild(circle2);
dispatchEvent
-
event
Dispatches an event into the event flow. The event target is the LEventDispatcher object upon which the dispatchEvent() method is called.
Parameters:
-
event
LEvent | StringThe Event object that is dispatched into the event flow. If the event is being redispatched, a clone of the event is created automatically. After an event is dispatched, its target property cannot be changed, so you must create a new copy of the event for redispatching to work.
Returns:
A value of true if the event was successfully dispatched. function MyEventObject(){ var self = this; LExtends(self,LSprite,[]); self.graphics.drawRect(1,"#000000",[0,0,100,100],true,"#000000"); self.graphics.drawRect(1,"#FF0000",[100,0,100,100],true,"#FF0000"); self.addEventListener(LMouseEvent.MOUSE_UP,self.onclick); self.addEventListener(MyEventObject.CLICK_LEFT,function(event){ trace("dispatchEvent"); }); self.addEventListener(MyEventObject.CLICK_RIGHT,function(event){ trace("dispatchEvent event.name = " + event.name); }); } MyEventObject.CLICK_LEFT = "click_left"; MyEventObject.CLICK_RIGHT = "click_right"; MyEventObject.prototype.onclick = function(event){ var self = event.clickTarget; if(event.selfX < 100){ self.dispatchEvent(MyEventObject.CLICK_LEFT); }else{ var event = new LEvent(MyEventObject.CLICK_RIGHT); event.name = "LEvent Test"; self.dispatchEvent(event); } }
focus
()
public
Get focus.
Example:
var theTextField = new LTextField();
theTextField.x = 20;
theTextField.y = 20;
theTextField.text = "Click the Enter Key, please!";
addChild(theTextField);
var theTextField1 = new LTextField();
theTextField1.x = 20;
theTextField1.y = 100;
theTextField1.setType(LTextFieldType.INPUT);
addChild(theTextField1);
theTextField1.addEventListener(LTextEvent.TEXT_INPUT, function (e) {
if(e.keyCode == 13){
theTextField2.focus();
}
});
var theTextField2 = new LTextField();
theTextField2.x = 20;
theTextField2.y = 140;
theTextField2.setType(LTextFieldType.INPUT);
addChild(theTextField2);
theTextField2.addEventListener(LTextEvent.TEXT_INPUT, function (e) {
if(e.keyCode == 13){
theTextField1.focus();
}
});
setTimeout(function () {
theTextField1.focus();
}, 200);
getBounds
-
targetCoordinateSpace
Returns a rectangle that defines the area of the display object relative to the coordinate system of the targetCoordinateSpace object.
Parameters:
-
targetCoordinateSpace
LDisplayObjectThe display object that defines the coordinate system to use.
Returns:
The rectangle that defines the area of the display object relative to the targetCoordinateSpace object's coordinate system.
getDataURL
()
Base64 Image
public
Get a string of base64-encoded image.
Returns:
a string of base64-encoded image.
getHeight
()
Float
public
Get the height of the display object, in pixels.
Returns:
the height of the display object.
Example:
var theTextField = new LTextField();
theTextField.text = "getHeight test";
addChild(theTextField);
trace(theTextField.getHeight());
getRootCoordinate
()
LPoint
public
Get the coordinates (Relative to the canvas).
Returns:
a LPoint object。
getWidth
()
Float
public
Get the width of the display object, in pixels.
Returns:
the width of the display object.
Example:
var theTextField = new LTextField();
theTextField.text = "getWidth test";
addChild(theTextField);
trace(theTextField.getWidth());
hasEventListener
-
type
Checks whether the LEventDispatcher object has any listeners registered for a specific type of event. This allows you to determine where an LEventDispatcher object has altered handling of an event type in the event flow hierarchy.
Parameters:
-
type
StringThe type of event.
Returns:
A value of true if a listener of the specified type is registered; false otherwise.
remove
()
public
Remove self from the parent container.
removeAllEventListener
()
public
Removes all the listeners from the LEventDispatcher object.
removeEventListener
-
type
-
listener
Removes a listener from the LEventDispatcher object. If there is no matching listener registered with the LEventDispatcher object, a call to this method has no effect.
Parameters:
-
type
StringThe type of event.
-
listener
FunctionThe listener object to remove.
setMultiline
-
value
-
height
Indicates whether field is a multiline text field. If the value is true, the text field is multiline; if the value is false, the text field is a single-line text field. In a field of type LTextFieldType.INPUT, determines whether the Enter key creates a new line (a value of false, and the Enter key is ignored).
Parameters:
-
value
BooleanIndicates whether field is a multiline text field. If the value is true, the text field is multiline.
-
height
IntThe height of a single-line text field.
Example:
var inputLayer = new LSprite();
inputLayer.graphics.drawRect(1,"#000000",[0, 0, 400, 150]);
var theTextField = new LTextField();
theTextField.setType(LTextFieldType.INPUT,inputLayer);
theTextField.setMultiline(true);
addChild(theTextField);
setType
-
type
-
obj
The type of the text field. Either one of the following LTextFieldType constants: LTextFieldType.DYNAMIC, which specifies a dynamic text field, which a user cannot edit, or LTextFieldType.INPUT, which specifies an input text field, which a user can edit.The default value is dynamic.
Parameters:
-
type
StringThe type of the text field.
-
obj
LSpriteThe object's shape.
Example:
var inputLayer = new LSprite();
inputLayer.graphics.drawRect(1,"#000000",[0, 0, 400, 30]);
var theTextField = new LTextField();
theTextField.setType(LTextFieldType.INPUT,inputLayer);
addChild(theTextField);
setWordWrap
-
value
-
height
Indicates whether the text field has word wrap. If the value of wordWrap is true, the text field has word wrap; if the value is false, the text field does not have word wrap. The default value is false.
Parameters:
-
value
BooleanIndicates whether the text field has word wrap.
-
height
IntThe height of a single-line text field.
Example:
var theTextField = new LTextField(); theTextField.setWordWrap(true); theTextField.width = 200; theTextField.text = "text\ntext\ntexttexttexttexttexttexttexttexttexttexttexttexttexttext"; addChild(theTextField);
updateInput
()
public
If the LTextField object's texttype is LTextFieldType.INPUT, copy the text to the inputbox.
Example:
var theTextField = new LTextField();
theTextField.x = 20;
theTextField.y = 20;
theTextField.text = "Click Enter Key to clear the text!";
addChild(theTextField);
var theTextField1 = new LTextField();
theTextField1.text = "test";
theTextField1.x = 20;
theTextField1.y = 100;
theTextField1.setType(LTextFieldType.INPUT);
addChild(theTextField1);
theTextField1.addEventListener(LTextEvent.TEXT_INPUT, function (e) {
if(e.keyCode == 13){
e.currentTarget.text = "";
e.currentTarget.updateInput();
e.preventDefault();
}
});
setTimeout(function () {
theTextField1.focus();
}, 200);
wind
()
public
Text animation
Example:
LInit(50, "legend", 800, 480, main);
function main () {
var theTextField = new LTextField();
theTextField.text = "wait click";
theTextField.x = 10;
theTextField.y = 10;
theTextField.size = 20;
addChild(theTextField);
var button = new LButtonSample1("wind test start");
button.textField = theTextField;
button.x = 10;
button.y = 100;
addChild(button);
button.addEventListener(LMouseEvent.MOUSE_DOWN, onclick);
}
function windOver(event){
var theTextField = event.target;
theTextField.removeEventListener(LTextEvent.WIND_COMPLETE, windOver);
theTextField.text = "wind over";
}
function onclick(event){
var theTextField = event.currentTarget.textField;
if (theTextField.hasEventListener(LTextEvent.WIND_COMPLETE)) {
theTextField.removeEventListener(LTextEvent.WIND_COMPLETE, windOver);
}
theTextField.text = "TEXTTEXTTEXTTEXTTEXTTEXTTEXTTEXTTEXTTEXT";
theTextField.speed = 3;
theTextField.wind();
theTextField.addEventListener(LTextEvent.WIND_COMPLETE, windOver);
}
Properties
alpha
Float
public
Indicates the alpha transparency value of the object specified. Valid values are 0 (fully transparent) to 1 (fully opaque). The default value is 1. Display objects with alpha set to 0 are active, even though they are invisible.
Default: 0
blendMode
String
public
A value from the LBlendMode class that specifies which blend mode to use. A bitmap can be drawn internally in two ways. If you have a blend mode enabled or an external clipping mask, the bitmap is drawn by adding a bitmap-filled square shape to the vector render. If you attempt to set this property to an invalid value, runtimes set the value to LBlendMode.NORMAL.
Default: null
color
String
public
Indicates the color of the text.
Default: "#000000"
Example:
var theTextField = new LTextField();
theTextField.text = "color test";
theTextField.x = 10;
theTextField.y = 10;
theTextField.color = "#FF0000";
addChild(theTextField);
displayAsPassword
Boolean
public
Specifies whether the text field is a password text field. If the value of this property is true, the text field is treated as a password text field and hides the input characters using asterisks instead of the actual characters. If false, the text field is not treated as a password text field.
Default: false
Example:
var theTextField = new LTextField();
theTextField.setType(LTextFieldType.INPUT);
theTextField.x = 10;
theTextField.y = 10;
theTextField.displayAsPassword = true;
addChild(theTextField);
filters
Array
public
An indexed array that contains each filter object currently associated with the display object.
Default: null
font
String
public
The name of the font for text in this text format, as a string. The default value is null, which means that Flash Player uses Times New Roman font for the text.
Default: Arial
Example:
var theTextField = new LTextField();
theTextField.text = "font test";
theTextField.x = 10;
theTextField.y = 10;
theTextField.font = "Georgia";
addChild(theTextField);
lineColor
String
public
The line's color of stroke.
Default: "#000000"
lineWidth
Int
public
The line's size of stroke.
Default: 1
mask
LDisplayObject
public
The calling display object is masked by the specified mask object. To ensure that masking works when the Stage is scaled, the mask display object must be in an active part of the display list. The mask object itself is not drawn. Set mask to null to remove the mask.
Default: null
mouseEnabled
Boolean
public
Specifies whether this object receives mouse, or other user input, messages. The default value is true, which means that by default any InteractiveObject instance that is on the display list receives mouse events or other user input events. If mouseEnabled is set to false, the instance does not receive any mouse events (or other user input events like keyboard events). Any children of this instance on the display list are not affected. To change the mouseEnabled behavior for all children of an object on the display list, use LDisplayObjectContainer.mouseChildren.
Example:
LGlobal.setDebug(true);
var button01 = new LButtonSample1("mouseEnabled=true");
button01.x = button01.y = 20;
addChild(button01);
button01.addEventListener(LMouseEvent.MOUSE_DOWN,function(e){
trace("button01 click");
});
var button02 = new LButtonSample1("mouseEnabled=false");
button02.x = 20;
button02.y = 150;
button02.mouseEnabled = false;
addChild(button02);
button02.addEventListener(LMouseEvent.MOUSE_DOWN,function(e){
trace("button02 click");
});
numLines
Int
public
Defines the number of text lines in a multiline text field. If setWordWrap(true), the number of lines increases when text wraps.
objectIndex
Int
public
ID of the object
rotate
Float
public
Indicates the rotation of the LDisplayObject instance, in degrees, from its original orientation. Values from 0 to 180 represent clockwise rotation; values from 0 to -180 represent counterclockwise rotation. Values outside this range are added to or subtracted from 360 to obtain a value within the range. For example, the statement my_video.rotate = 450 is the same as my_video.rotate = 90.
Default: 0
scaleX
Float
public
Indicates the horizontal scale (percentage) of the object as applied from the registration point. The default registration point is (0,0). 1.0 equals 100% scale.
Default: 1
scaleY
Float
public
Indicates the vertical scale (percentage) of an object as applied from the registration point of the object. The default registration point is (0,0). 1.0 is 100% scale.
Default: 1
size
Int
public
The size in pixels of text in this text format.
Default: 11
Example:
var theTextField = new LTextField();
theTextField.text = "size test";
theTextField.x = 10;
theTextField.y = 10;
theTextField.size = 20;
addChild(theTextField);
speed
Int
public
The Text animation's speed.
Default: 0
Example:
LInit(50, "legend", 800, 480, main);
function main () {
var theTextField = new LTextField();
theTextField.text = "wait click";
theTextField.x = 10;
theTextField.y = 10;
theTextField.size = 20;
addChild(theTextField);
var button = new LButtonSample1("wind test start");
button.textField = theTextField;
button.x = 10;
button.y = 100;
addChild(button);
button.addEventListener(LMouseEvent.MOUSE_DOWN, onclick);
}
function windOver(event){
var theTextField = event.target;
theTextField.removeEventListener(LTextEvent.WIND_COMPLETE, windOver);
theTextField.text = "wind over";
}
function onclick(event){
var theTextField = event.currentTarget.textField;
if (theTextField.hasEventListener(LTextEvent.WIND_COMPLETE)) {
theTextField.removeEventListener(LTextEvent.WIND_COMPLETE, windOver);
}
theTextField.text = "TEXTTEXTTEXTTEXTTEXTTEXTTEXTTEXTTEXTTEXT";
theTextField.speed = 3;
theTextField.wind();
theTextField.addEventListener(LTextEvent.WIND_COMPLETE, windOver);
}
stroke
String
public
Text effects of stroke.
Default: false
Example:
var theTextField = new LTextField();
theTextField.text = "stroke test";
theTextField.size = 50;
theTextField.stroke = true;
theTextField.lineWidth = 2;
theTextField.lineColor = "#FF0000";
addChild(theTextField);
text
String
public
A string that is the current text in the text field. Lines are separated by the carriage return character ('\n').
textAlign
String
public
Indicates the alignment of the paragraph(horizontal).
Default: left
textBaseline
String
public
Indicates the alignment of the paragraph(vertical).
Default: top
type
String
public
type of the object
Default: LTextField
visible
Boolean
public
Whether or not the display object is visible. Display objects that are not visible are disabled. For example, if visible=false for an LInteractiveObject instance, it cannot be clicked.
Default: true
weight
String
public
Specifies whether the text is boldface.
Default: normal
Example:
var theTextField = new LTextField();
theTextField.text = "weight test";
theTextField.x = 10;
theTextField.y = 10;
theTextField.weight = "bolder";
addChild(theTextField);
width
Int
public
When the text field has word wrap , you can set the width of the display object, in pixels.
Default: 150
x
Float
public
Indicates the x coordinate of the LDisplayObject instance relative to the local coordinates of the parent LDisplayObjectContainer. If the object is inside a LDisplayObjectContainer that has transformations, it is in the local coordinate system of the enclosing LDisplayObjectContainer. Thus, for a LDisplayObjectContainer rotated 90° counterclockwise, the LDisplayObjectContainer's children inherit a coordinate system that is rotated 90° counterclockwise. The object's coordinates refer to the registration point position.
Default: 0
y
Float
public
Indicates the y coordinate of the LDisplayObject instance relative to the local coordinates of the parent LDisplayObjectContainer. If the object is inside a LDisplayObjectContainer that has transformations, it is in the local coordinate system of the enclosing LDisplayObjectContainer. Thus, for a LDisplayObjectContainer rotated 90° counterclockwise, the LDisplayObjectContainer's children inherit a coordinate system that is rotated 90° counterclockwise. The object's coordinates refer to the registration point position.
Default: 0
Events
LEvent.ENTER_FRAME
[broadcast event] Dispatched when the playhead is entering a new frame.
LFocusEvent.FOCUS_IN
Dispatched after a LTextField object gains focus.
LFocusEvent.FOCUS_OUT
Dispatched after a LTextField object loses focus.
LMouseEvent.DOUBLE_CLICK
Disabled.
LMouseEvent.MOUSE_DOWN
Disabled.
LMouseEvent.MOUSE_MOVE
Disabled.
LMouseEvent.MOUSE_OUT
Disabled.
LMouseEvent.MOUSE_OVER
Disabled.
LMouseEvent.MOUSE_UP
Disabled.