Pergunta

Here's what I have so far,

<?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="init()">
    <fx:Declarations>
        <!-- Place non-visual elements (e.g., services, value objects) here -->
    </fx:Declarations>

    <fx:Script>
        <![CDATA[
            import spark.components.CheckBox;

            private function init():void
            {
                var _cb:spark.components.CheckBox= new spark.components.CheckBox();
                _cb.name = "alsowhatever";
                _cb.y = 40;
                addChild(_cb);

            }
        ]]>
    </fx:Script>

</s:Application>

the page does not display the CheckBox as expected, could someone point out where I have gone wrong. (Flash Builder lists my version of Flex as 4.1)

Foi útil?

Solução

That's a Spark Application: you should use addElement() instead of addChild(). Use addChild() in mx components only.

Admitted: it's somewhat confusing. Why is there still the public function addChild() if I cannot use it? Well that's because all components extend UIComponent (including the Spark components). So addChild() is only still there for legacy reasons.

Outras dicas

You must use addElement() instead of addChild().

You have _cb.name It should read ad follows:

            var _cb:spark.components.CheckBox= new spark.components.CheckBox();
            _cb.label = "alsowhatever";
            _cb.y = 40;
            addElement(_cb);

Neil

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top