Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Aug 2009
    Posts
    4
    Thanks
    1
    Thanked 0 Times in 0 Posts

    How to dynamically add controls to a Panel

    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,

  • #2
    Senior Coder nikos101's Avatar
    Join Date
    Dec 2006
    Location
    London
    Posts
    1,007
    Thanks
    59
    Thanked 10 Times in 10 Posts
    use the

    idOfYourContainer.addChild(childID) method



  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •