LStyleSheet Class
使用 LStyleSheet 类可以创建包含文本格式设置规则(例如,字体大小、颜色和其他格式样式)的 LStyleSheet 对象。然后,可以将样式表定义的样式应用到包含 HTML 或 XML 格式文本的 LTextField 对象。根据 LStyleSheet 对象定义的标签样式自动设置 LTextField 对象中文本的格式。可以使用文本样式来定义新的格式标签,重新定义内置的 HTML 标签,或创建可应用到某些 HTML 标签的样式类。
要对一个 LTextField 对象应用样式,请将该 LStyleSheet 对象赋给 LTextField 对象的 styleSheet 属性。
注意:具有样式表的文本字段不可编辑。
下表显示目前支持的层叠样式表 (CSS) 属性和值。
CSS 属性 | 用法和支持的值 |
---|---|
color | 颜色。 |
font-family | 字体名称。 |
font-size | 文本大小。 |
font-style | 可识别的值为 normal 和 italic。 |
font-weight | 可识别的值为 normal 和 bold。 |
text-decoration | 可识别的值为 none 和 underline。 |
Constructor
LStyleSheet
()
public
Example:
var styleSheet = new LStyleSheet();
styleSheet.setStyle(".test","{color:#FF0000;font-size:40}");
styleSheet.setStyle("myText","{color:#008800;font-size:30}");
var theTextField = new LTextField();
theTextField.htmlText = "ABC<span class='test'>ABC<myText><i>ABC</i>ABC</myText>ABC</span>ABC<b>ABC</b><u>ABC</u>";
theTextField.x = 10;
theTextField.y = 100;
theTextField.styleSheet = styleSheet;
addChild(theTextField);
Methods
callParent
(
public
-
functionName
-
arguments
调用父类的函数。
Parameters:
-
functionName
String函数名
-
arguments
Array固定值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
}
getStyle
(
Object
public
-
styleName
返回与名为 styleName 的样式相关联的样式对象的一个副本。如果没有与 styleName 相关联的样式对象,则返回 null。
Parameters:
-
styleName
String一个字符串,该字符串指定要检索的样式的名称。
Returns:
Object:
一个对象。
setStyle
(
public
-
styleName
-
styleObject
将具有指定名称的新样式添加到样式表对象中。如果该样式表中没有指定名称的样式,将添加该样式。如果该样式表中已经有指定名称的样式,将替换该样式。如果 styleObject 参数为 null,则删除指定名称的样式。
Parameters:
-
styleName
String一个字符串,用于指定要添加到样式表中的样式的名称。
-
styleObject
String一个说明样式的对象,或 null。
Example:
var styleSheet = new LStyleSheet();
styleSheet.setStyle(".test","{color:#FF0000;font-size:40}");
styleSheet.setStyle("myText","{color:#008800;font-size:30}");
var theTextField = new LTextField();
theTextField.htmlText = "ABC<span class='test'>ABC<myText><i>ABC</i>ABC</myText>ABC</span>ABC<b>ABC</b><u>ABC</u>";
theTextField.x = 10;
theTextField.y = 100;
theTextField.styleSheet = styleSheet;
addChild(theTextField);
Properties
objectIndex
Int
public
对象的ID