如何在Flex中以编程方式创建删除线文本?

时间:2011-10-19 01:22:44

标签: flex

我知道我可以在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.

1 个答案:

答案 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>