API Docs for: 1.10.1 最后更新日期:2016年03月28日
Google搜索   
Show:

LStyleSheet Class

Extends LObject
Defined in: text/LStyleSheet.js:1

Available since 1.9.8

使用 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

Defined in text/LStyleSheet.js:1

Available since 1.9.8

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);

Item Index

Properties

Methods

callParent

(
  • functionName
  • arguments
)
public

Inherited from LObject: utils/LObject.js:22

Available since 1.6.0

调用父类的函数。

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

(
  • styleName
)
Object public

Defined in text/LStyleSheet.js:85

Available since 1.9.8

返回与名为 styleName 的样式相关联的样式对象的一个副本。如果没有与 styleName 相关联的样式对象,则返回 null。

Parameters:

  • styleName String

    一个字符串,该字符串指定要检索的样式的名称。

Returns:

Object:

一个对象。

setStyle

(
  • styleName
  • styleObject
)
public

Defined in text/LStyleSheet.js:44

Available since 1.9.8

将具有指定名称的新样式添加到样式表对象中。如果该样式表中没有指定名称的样式,将添加该样式。如果该样式表中已经有指定名称的样式,将替换该样式。如果 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

Inherited from LObject: utils/LObject.js:11

Available since 1.6.0

对象的ID