3 Replies Latest reply on Sep 16, 2009 7:14 AM by jolpes

    How to instance an mx-component

    jolpes

      Hi!

       

      I have the following problem.

       

      1. I got a mx:ViewStack (main) with two components: an mx:HBox and a custom made (app:NewMailBox).

      2. In the main application I want to open the app:NewMailBox and initate it with a mail object

       

      Probelm

      The components in app:NewMailBox is null the first time I call method newMail.setMail() (please see code below). The next time i works.

       

      Conslusion

      It seems like the mx components must be shown to be created.

       

      Question

      How do I create the instances of a mx components in a viewstack without showing it first. Please see code below for some clarification ;-)

       

      <mx:VBox>

       

          <mx:ViewStack id="mainStack">

                <mx:HBox>

                    <mx:DataGrid id="mailGrid" dataProvider="{mailList}"

                               click="mainStack.selectedIndex = 1; newMail.setMail(mailGrid.selectedItem);">

                               //The newMail mx components are null the first time setMail() method is called and the newMailBox component is shown

                               //The second time this meethod is called all mx child components to newMailBox is created and it works perfectly
                        <mx:columns>
                                <mx:DataGridColumn dataField="@subject" headerText="Title"/>
                        </mx:columns>
                    </mx:DataGrid>

                </mx:HBox>

       

                <app:NewMailBox id="newMail"/>

          <mx:ViewStack>

      </mx:VBox>

       

      Best regards,

      Mattias