2 Replies Latest reply on Aug 14, 2009 9:16 PM by Gregory Lafrance

    How to dynamically add controls to a Panel

    csr_1978

      Hi,


      I have two classes Main.mxml and User.mxml as below


      Main.mxml

      -----------------

      <?xml version="1.0" encoding="utf-8"?>
      <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" xmlns:local="*">
      <mx:HBox id="box">
      <mx:Panel id="panel1" title="panel 1">
      <local:User/>

      </mx:Panel>
      <mx:Panel id="panel2" title="panel 2">
      <mx:Label id="label1" text="Label 1"/>
      </mx:Panel>
      </mx:HBox>  
      </mx:Application>


      User.mxml

      ----------------

      <?xml version="1.0" encoding="utf-8"?>
      <mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml" width="400" height="300">
      <mx:Script>
      <![CDATA[
      private function btn1Handler():void
      {
      trace(parent.parent.getChildByName('panel2'));

      // Add a control to the panel2
      }
      ]]>
      </mx:Script>
      <mx:Button label="button 1" click="btn1Handler();"/>
      </mx:Canvas>


      If i click button 1 i shd add some control (like button or label etc...) to panel 2. How do i acheive this/


      Thanks,