6 Replies Latest reply on Nov 9, 2010 7:51 AM by jfb00

    how to use an ArrayCollection of another formulario.mxml?

    giba_f Level 1

      I have two forms:

       

      1) Main.mxml:

      <?xml version="1.0" encoding="utf-8"?>
      <mx:Application xmlns:mx="
      http://www.adobe.com/2006/mxml" layout="absolute" >


          <mx:DataGrid height="235" width="610" id="GridPar" dataProvider="{aCols}" >
              <mx:columns>
                  <mx:DataGridColumn  width="150"  headerText="Variavel"  dataField="variavel" />
                  <mx:DataGridColumn  width="80"   headerText="Tipo"      dataField="tipo"     />
                  <mx:DataGridColumn  width="500"  headerText="Conteudo"  dataField="conteudo" />
              </mx:columns>
          </mx:DataGrid>

          <mx:Script>
              <![CDATA[

                  [Bindable] public  var aCols:ArrayCollection;

              ]]>
          </mx:Script>


      </mx:Application>

          <mx:Script>
              <![CDATA[


                  private function Start():void {
                      var Obj:Object = new Object();
                      Obj.variavel  = "Name";
                      Obj.tipo      = "C";
                      Obj.conteudo  = "John";
                      aColsPara.addItem( Obj ); //parentDocument.aColsPara.addItem( Obj );
                  }
                 

              ]]>
          </mx:Script>


      </mx:Application>

      2) Form..mxml:
      <?xml version="1.0" encoding="utf-8"?>
      <mx:TitleWindow xmlns:mx="
      http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="Start()" >

       

       

      how to use the form "aColsPara" 2?

       

       

      I thank you for help: THANK YOU ...

       

      Gilberto

       

        • 1. Re: how to use an ArrayCollection of another formulario.mxml?
          BhaskerChari Level 4

          @Gilberto,

           

           

          I don't find where in your code you decalred aColsPara in your application.

           

          If I understand correctly you want to access aCols  ArrayCollection declared in the main mxml file in the Form.mxml if so then you can try this...

           

          </mx:TitleWindow>

           

          Thanks,

          Bhasker

          2) Form..mxml:
          <?xml version="1.0" encoding="utf-8"?>
          <mx:TitleWindow xmlns:mx="
          http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="Start()" >    

          <mx:Script>
                  <![CDATA[

                       import mx.core.Application;


                      private function Start():void {
                          var Obj:Object = new Object();
                          Obj.variavel  = "Name";
                          Obj.tipo      = "C";
                          Obj.conteudo  = "John";
                          Application.application.aCols.addItem( Obj );
                      }
                     

                  ]]>
              </mx:Script>

          • 2. Re: how to use an ArrayCollection of another formulario.mxml?
            Tanu Jain

            In main.mxml, "aCols" can be declared as "static public var". This way it can be used as main.aCols in Form.mxml.

            or you create an instance of main.mxml in form.mxml and use its public variables.

             

            However, this is not the preferred way of handling variables. Depending upon the application, custom events can be used to share data values among child-parent mxmls.

             

            Regards,

            Tanu

            • 3. Re: how to use an ArrayCollection of another formulario.mxml?
              giba_f Level 1

              ops...

               

              sorry, some problem in my post. This correct it's:

               

              I have two forms:

               

              1) Main.mxml:

              <?xml version="1.0" encoding="utf-8"?>
              <mx:Application xmlns:mx="
              http://www.adobe.com/2006/mxml" layout="absolute" >

                  <mx:DataGrid height="235" width="610" id="GridPar" dataProvider="{aCols}" >
                      <mx:columns>
                          <mx:DataGridColumn  width="150"  headerText="Variavel"  dataField="variavel" />
                          <mx:DataGridColumn  width="80"   headerText="Tipo"      dataField="tipo"     />
                          <mx:DataGridColumn  width="500"  headerText="Conteudo"  dataField="conteudo" />
                      </mx:columns>
                  </mx:DataGrid>

               

                  <mx:Script>
                      <![CDATA[

               

                          [Bindable] public  var aCols:ArrayCollection;

               

                      ]]>
                  </mx:Script>

               

              </mx:Application>

               

               

              2) Form..mxml:
              <?xml version="1.0" encoding="utf-8"?>
              <mx:TitleWindow xmlns:mx="
              http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="Start()" >

                  <mx:Script>
                      <![CDATA[


                          private function Start():void {
                              var Obj:Object = new Object();
                              Obj.variavel  = "Name";
                              Obj.tipo      = "C";
                              Obj.conteudo  = "John";
                              aCols.addItem( Obj ); //parentDocument.aColsPara.addItem( Obj );
                          }
                         

                      ]]>
                  </mx:Script>

              </mx:Application>

               

              Tanu Jain ? I'm trying "static public var", but not working...

               

              Gilberto

               

               

               

              • 4. Re: how to use an ArrayCollection of another formulario.mxml?
                jfb00 Level 3

                Hi,

                Are you calling the second form with PopUpManager?

                 

                Johnny

                Please rate answers

                • 6. Re: how to use an ArrayCollection of another formulario.mxml?
                  jfb00 Level 3

                  Then wen you call the popupwindows add a variable with value this like:

                  win=MyScreen(PopUpManager.createPopUp(this,MyScreen,true));
                  win.mainApp = this;

                   

                  In the window form declare that variable as:

                  [Bindable] public var mainApp:Object = null;

                   

                  Now you can get you array like:

                  mainApp.myArray.addItem();

                   

                  Johnny

                  Please rate answers