简体   繁体   中英

weird behaviour with addChild

i am trying to add one Box to my application using the following code

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" minWidth="955" minHeight="600"
                >
    <mx:HBox height="100%" width="100%" backgroundColor="red"  borderColor="black"/>
    <mx:Script>
        <![CDATA[
            import mx.collections.ArrayCollection;
            import mx.containers.Box;
            import mx.events.FlexEvent;


            protected function button1_clickHandler():void
            {
                var box:Box = new Box();
                box.setStyle("backgroundColor","blue");
                box.height = 100;
                box.width = 100;
                //box.addChild(new Button());
                addChild(box);
                trace("children  "+numChildren);
            }

        ]]>
    </mx:Script>
    <mx:Button label="click" click="button1_clickHandler()" x="200" y="200" />
</mx:Application>

this code is work in flexBuilder.but it doesn't work while compiling in command prompt(using mxmlc command). please suggest me on this issue, because my work is fully depending on command prompt.

thanks in advance vengatesh s

This totally depends on the compiler you are using. If you are using the Flex 4+ compiler I would suggest you to try using addElement instead of addChild. The same code above just changes to

protected function button1_clickHandler():void
{
    var box:Box = new Box();
    box.setStyle("backgroundColor","blue");
    box.height = 100;
    box.width = 100;
    /********** ----------- CHANGE----------------------********/
    // This is the only change from your code
    addElement(box);
    /********** ----------- CHANGE----------------------********/
    trace("children  "+numChildren);
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM