2011-10-19 38 views
0

我知道我可以在MXML做到這一點:如何在Flex中以編程方式創建刪除線文本?

<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
<?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> 
+0

這工作完全!謝謝:) 它肯定也解釋了很多。 – Titus

+1

Flex預編譯器增加了許多魔力--MXML屬性並不總是等同於類成員。如果您無法解析MXML屬性,請檢查樣式屬性。另外,如果需要查看mxmlc編譯器如何將MXML文檔轉換爲ActionScript,請添加「-keep」編譯器參數以保留生成的ActionScript。 –

+0

感謝您的補充信息;這是非常寶貴的。我一定會那樣做的! – Titus

相關問題