2 Replies Latest reply on Oct 26, 2010 7:28 AM by bignuttjob

    Error with addChild

    nuttJob2010
      Hi,

       

      I'm trying to create some objects at runtime in AS3 rather than at authortime in the Flex part of the application. My problem is adding them to the stage. The addChild method fails when I add the Textfield to the Panel, and I've tried using "this.addchild", and AddElement, but either it throws an exception or won't compile. The error message is:

       

      [Fault] exception, information=Error: addChild() is not available in this class. Instead, use addElement() or modify the skin, if you have one.

       

      Here's the code:

       

      Code:
      <?xml version="1.0" encoding="utf-8"?>
      <s:Application xmlns:<links removed as this is my 1st post;-( minWidth="955" minHeight="620"
                        creationComplete="app_creationCompleteHandler(event)">
           
                
           <fx:Script>
                <![CDATA[
                     import mx.events.FlexEvent;                              
                     
                     protected function app_creationCompleteHandler(event:FlexEvent):void
                     {
                          var tf:TextField = new TextField();
                          tf.width = 100;
                          tf.height = 100;
                          tf.x = 100;
                          tf.y = 200;
                          tf.text = "My text";
                          tf.textColor = 0xffff00;
                          
                          pa.addChild(tf);
                     }     
                ]]>
           </fx:Script>
      
           <s:Panel id="pa" y="10" width="800" height="600" horizontalCenter="-68">
                     <s:Button x="100" y="100" visible="true" id="idWelcome" label="Click to start" useHandCursor="true" buttonMode="true" mouseChildren="false"/>
           </s:Panel>
           
      </s:Application>
      Sorry if this is more a Flex question that AS3.
      Thanks
      TimN