我知道我可以在MXML中执行此操作:
<s:CheckBox label="Some Text" lineThrough="true" />
但是我怎么能以编程方式做同样的事情呢?以下不起作用:
var newCheckBox:CheckBox = new CheckBox;
newCheckBox.label = "Some Text";
newCheckBox.lineThrough = "true"; // Flex code help doesn't see "lineThrough"
dummyContainer.addElement(newCheckBox); // Just some dummy container to add the element to.
答案 0 :(得分:1)
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
minWidth="955"
minHeight="600"
creationComplete="creationCompleteHandler(event)">
<fx:Script>
<![CDATA[
import mx.events.FlexEvent;
import spark.components.CheckBox;
protected function creationCompleteHandler(event:FlexEvent):void
{
var checkBox:CheckBox = new CheckBox();
checkBox.label = "Some text";
checkBox.setStyle("lineThrough", true);
addElement(checkBox);
}
]]>
</fx:Script>
</s:Application>