2 Replies Latest reply on Oct 30, 2009 6:58 AM by DennisTh

    addChild doesn't effect for some reason REFdn2065133102

    DennisTh Level 1

      In small test application I have the follow object… stack

       

      The “Main.mxml” loads the EntryClass.as -> “class EntryClass” (that doesn’t extends anything) -> “public static function Main()”.

       

      This EntryClass.Main() function is doing the follow:

       

            var mxmlApp:Application = Application(Application.application);

            var mainAppClass:MainAppClass=new MainAppClass();

            mxmlApp.addChild(mainAppClass);

           

      So the mainAppClass is loaded.

      Now the MainAppClass extends the UIComponent and in its constructor does this:

       

            var buttonFromMainClass:Button=new Button();

            buttonFromMainClass.x=20;buttonFromMainClass.y=20;buttonFromMainClass.label="hello world";

       

      to add it to stage I call

       

            addChild(buttonFromMainClass);

       

      and here is the problem! The button is not appeared on the stage, but using this code:

       

            Application(Application.application).addChild(buttonFromMainClass);

       

      the button is added to the stage and it is visible.

       

      Why the button is not added to the stage with the simple addChild? Where am I wrong?

       

      Something that might be help, in EntryClass.Main() if I create a button and add it with the mxmlApp.addChild, the button is added and appeared on the stage normally, so there is no problem with the use of mxmlApp.addChild.

       

      Best regards

      Dennis