1 Reply Latest reply on Jul 24, 2009 1:53 PM by Flex harUI

    Question Regarding Component Inheritance and Visibility


      I am a Flex noob, so it is possible I am using incorrect verbiage...here is my problem...


      I have a GenericForm.mxml custom component, which is pretty much an empty HBox and it has a session property.
      Then I have several specific forms (components) that extend my GenericForm, i.e., HotelForm.mxml, MealForm.mxml, etc.


      Each specific form starts out with


      And each specific form has an actual <mx:Form... etc. in it.

      Now, I have a higher level WindowHome.mxml in which i am trying to instantiate the specific form and then show/hide
      it, the hotel form in this case.


      In my WindowHome actionscript, i have the following snippet:


                  var specificForm:GenericForm = null;
                  if (session.currItem.itemtype == "H")
                      specificForm = new HotelForm();
                  specificForm.session = _session;
                  box.formContainer.form = specificForm;
                  box.formContainer.form.visible = true;
      The problem is that the no form is becoming visible in box.formContainer with the snippet above.


      box.formContainer looks something like this...


          <controls:ReportList id="reportList" session="{session}" visible="false"/>
          <controls:GenericForm id="form" session="{session}" visible="false"/>
      For testing purposes, in my GenericForm, I added.


      <mx:Text text="HELLO CAN YOU SEE THIS"/>


      When I remove the following line from the snippet above:


      box.formContainer.form = specificForm;
      the code works in so much as the generic form becomes visible and i can see "HELLO CAN YOU SEE THIS".
      But when i set the box.formContainer.form equal to specificForm, nothing is made visible.


      I must be missing something pretty basic here.  Can you help me understand why this doesn't work?


      Thanks very much.

        • 1. Re: Question Regarding Component Inheritance and Visibility
          Flex harUI Adobe Employee

          There are two "trees" in Flex.  The MXML DOM tree has references to various other MXML files and components that might have references to child objects.  The DisplayObject tree has references of parent DisplayObjectContainers to their child DisplayObjects.


          Your .form property is in the MXML DOM, the DisplayObject tree is set up for you under the covers by the framework.  Your code is only manipulating the MXML DOM tree and not the DisplayObject tree.  You would need to removeChild the original GenericForm and addChildAt the new form because it is the DisplayObject tree that dictates what you see.  The MXML DOM tree dictates how you manage those DisplayObjects in your code.


          Alex Harui

          Flex SDK Developer

          Adobe Systems Inc.

          Blog: http://blogs.adobe.com/aharui