5 Replies Latest reply on Oct 2, 2009 3:21 PM by ShardulSingh

    how to display TitleWindow from main application

    Alex-SM Level 1

      Hi,

       

      I have two mxml files, file1.mxml (the main application) and file2.mxml (a TitleWindow).    How can I display file2.mxml from file1.mxml in an actionscript function?

       

      =========================================================

      file1.mxml

      <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml">

      <mx:Script>
          <![CDATA[

                private function call_file2():void

                {

                     // displaying file 2

                }

      ...


      <mx:Button label="Enter" click="call_file2()"/>

      </mx:Application>

      =========================================================

      file2.mxml

      <mx:TitleWindow xmlns:mx="http://www.adobe.com/2006/mxml">

      .....


      </mx:TitleWindow>

      =========================================================

        • 1. Re: how to display TitleWindow from main application
          ShardulSingh Level 3

          Pls find the code for your function.If you have any issue with this pls let me know.


               private function call_file2():void
               {
                  var myPopUp:file2= file2(PopUpManager.createPopUp(this, file2, true));
                   myPopUp.move(((Application.application.width/2)-(myPopUp.width/2)),
                   ((Application.application.height/2)-(myPopUp.height/2)));
               }

           

           

           


          With Regards,
          Shardul Singh Bartwal

          • 2. Re: how to display TitleWindow from main application
            ShardulSingh Level 3

                If you don’t want in the popup style then use the code below.

                private function call_file2():void
                        {
                           
                        var myCustomComponent : file2 = new file2();
                        myCustomComponent.name = "myCustomComponent";
                        if(this.getChildByName("myCustomComponent") == null)
                        {
                            this.addChild(myCustomComponent);   
                        }
                        }

             


                With Regards,
                Shardul Singh Bartwal

            • 3. Re: how to display TitleWindow from main application
              Alex-SM Level 1

              Thanks a lot. I chose the second. It works great.

              • 4. Re: how to display TitleWindow from main application
                Alex-SM Level 1

                There is one problem here.


                file2.mxml contains a ViewStack with two canvases. Each canves has a datagrid that are being filled with data from mysql database.

                Your suggetsion only create an empty page of file2.mxml, i.e. none of the actions defined in this file2.mxml works.

                 

                what's a way to move from file1.mxml to file2.mxml (with all actions) and not just to display file2.mxml in file1.mxml?

                 

                Thanks

                • 5. Re: how to display TitleWindow from main application
                  ShardulSingh Level 3

                  Hi,

                  It will work fine If you will define your file2.mxml properly.You can relplace your file2.mxml code with the code below,and it will work fine.

                  Get the data from your backend where I m settting the dataprovider of the datagrids. You dont require to do any change in file1.mxml.

                  Replace the containt of file2.mxml with the code below.

                   

                   

                  file2.mxml

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

                  <mx:TitleWindow xmlns:mx="http://www.adobe.com/2006/mxml"

                        width="400" height="300" creationComplete="onCreationComplete()">

                        <mx:Script>

                  <![CDATA[

                        import mx.collections.ArrayCollection;

                   

                        private var acDg1 : ArrayCollection = new ArrayCollection([

                        {Name:"Martin",Age:"21",Dept:"Dept1"},

                        {Name:"Devid",Age:"22",Dept:"Dept2"},

                        {Name:"Ali",Age:"23",Dept:"Dept3"}

                        ]);

                       

                        private var acDg2 : ArrayCollection = new ArrayCollection([

                        {Name:"Jojo",Age:"31",Dept:"Dept11"},

                        {Name:"Cris",Age:"32",Dept:"Dept22"},

                        {Name:"Henry",Age:"33",Dept:"Dept33"}

                        ]);

                       

                       

                  private function onCreationComplete():void

                  {

                        dg1.dataProvider = acDg1;

                        dg2.dataProvider = acDg2;

                  }

                   

                  private function switchCanvas():void

                  {

                        if(vstk.selectedIndex == 0)

                        {

                              vstk.selectedIndex = 1;

                        }

                        else

                        {

                              vstk.selectedIndex =0;

                        }

                  }

                   

                  ]]>

                  </mx:Script>

                  <mx:ViewStack id="vstk" width="100%" height="100%" creationPolicy="all">

                        <mx:Canvas id="can1">

                              <mx:VBox>

                                    <mx:Label text="First Canvas"/>

                                    <mx:DataGrid id="dg1">

                                    <mx:columns>

                                    <mx:DataGridColumn headerText="Name" dataField="Name"/>

                                    <mx:DataGridColumn headerText="Age" dataField="Age"/>

                                    <mx:DataGridColumn headerText="Dept" dataField="Dept"/>

                                    </mx:columns>

                                    </mx:DataGrid>

                              </mx:VBox>

                        </mx:Canvas>

                       

                        <mx:Canvas id="can2">

                              <mx:VBox>

                                    <mx:Label text="Second Canvas"/>

                                    <mx:DataGrid id="dg2">

                                    <mx:columns>

                                    <mx:DataGridColumn headerText="Name" dataField="Name"/>

                                    <mx:DataGridColumn headerText="Age" dataField="Age"/>

                                    <mx:DataGridColumn headerText="Dept" dataField="Dept"/>

                                    </mx:columns>

                                    </mx:DataGrid>

                              </mx:VBox>

                        </mx:Canvas>     

                  </mx:ViewStack>

                   

                  <mx:Button label="Change To Another Canvas" click="switchCanvas()"/>

                  </mx:TitleWindow>

                   

                   

                   

                   

                  with Regards,

                  Shardul Singh Bartwal