2 Replies Latest reply on Aug 24, 2009 2:05 PM by ThaJock1

    Dynamic Panels

    ThaJock1

      I am trying to dynamically change a panel with a differenc panel on mouseDown but it's not working as I though it would.  Here is the code:

       

      <?xml version="1.0" encoding="utf-8"?>
      <mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
      <mx:Script>
          <![CDATA[
              import mx.containers.Panel;
             
              public function UpdatePanel():void {
                  var newPanel1:Panel = new Panel();
                  newPanel1.title = "New Panel 1";
                  newPanel1.percentWidth = 100;
                  newPanel1.percentHeight = 100;
                  panel1 = newPanel1;
              }
          ]]>

      </mx:Script>
      <mx:VBox width="100%" height="100%">
          <mx:VDividedBox width="100%" height="100%">
              <mx:Panel id="panel1" width="100%" height="100%"/>
              <mx:Panel id="panel2" width="100%" height="100%"/>
          </mx:VDividedBox>
         
          <mx:Button label="Update" mouseDown="UpdatePanel()"/>       
      </mx:VBox>

      </mx:WindowedApplication>

       

       

      I am not getting any errors but panel1 doesn't update onMouseDown.  If anyone can help I would appreciate it.

        • 1. Re: Dynamic Panels
          ShardulSingh Level 3

          Hi,

          You can not replace the earlier added Panel in this way,for this you have to remove the earlier added panel first.

          Pls find the code below,and let me know if this helps you.

           

           

           

          <?xml version="1.0" encoding="utf-8"?>

          <mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">

          <mx:Script>

              <![CDATA[

                  import mx.containers.Panel;

                 

                  public function UpdatePanel():void {

                      var newPanel1:Panel = new Panel();

                      newPanel1.title = "New Panel 1";

                      newPanel1.percentWidth = 100;

                      newPanel1.percentHeight = 100;

                      VDividedBox.removeChild(panel1);

                      VDividedBox.addChild(newPanel1);

                  }

              ]]>

          </mx:Script>

          <mx:VBox width="100%" height="100%">

              <mx:VDividedBox id="VDividedBox" width="100%" height="100%">

                  <mx:Panel id="panel1" width="100%" height="100%"/>

                  <mx:Panel id="panel2" width="100%" height="100%"/>

              </mx:VDividedBox>

             

              <mx:Button label="Update" mouseDown="UpdatePanel()"/>       

          </mx:VBox>

           

          </mx:WindowedApplication>

           

           

           

           

          with Regards,

          Shardul Singh Bartwal

          • 2. Re: Dynamic Panels
            ThaJock1 Level 1

            Thanks a lot man.  I will just create a function that will create the panel on the fly and add it to the DividedBox.  I really appreciate you taking the time to reply to this post because Flex is such a huge framework that It's kind of hard to do one thing without knowing the rule of something else.  I have been working with flash as3 over the past year and now trying to dig into flex.

             

            Thanks again