5 Replies Latest reply on Jul 15, 2009 9:44 AM by Gregory Lafrance

    Passing ArrayCollection From 1 Component to Another

    Trojan84

      So I know how to pass variables from component to popup, but the same process doesn't work from component to component for me.

       

      here is how it is setup.

       

      MainPage

       

       

        <mx:ViewStack id="TopMenu" width="980" height="100%" creationPolicy="all">
                    <ns1:Mainpage label="Main Page" width="100%" height="100%" showEffect="WipeUp" hideEffect="WipeUp"/>
                <ns1:Search label="Search For" width="100%" height="100%" showEffect="WipeUp" hideEffect="WipeUp"/>
                <ns1:Listing label="list" For" width="100%" height="100%" showEffect="WipeUp" hideEffect="WipeUp"/>
                               
                 
              </mx:ViewStack>

       

      Search

       

      <mx:DataGrid     id="BriefcaseGrid"
                                  allowMultipleSelection="false"
                                  dataProvider="{ResultListing}"
                                    width="275"
                                    selectable="true"
                                     selectionColor="haloBlue"
                                      variableRowHeight="true"
                                     
                                       fontSize="15"
                                       rowHeight="40"
                                      
                                     >
                      <mx:columns>
                          <mx:DataGridColumn dataField="Name" headerText=" Name"/>
                          <mx:DataGridColumn dataField="Date" headerText="Date"/>    
       
                      </mx:columns>   
                  </mx:DataGrid>

       

      List

       

      <mx:DataGrid     id="BriefcaseGrid"
                                   allowMultipleSelection="false"
                                   dataProvider="{Search.ResultListing}"
                                     width="275"
                                     selectable="true"
                                      selectionColor="haloBlue"
                                       variableRowHeight="true"
                                      
                                        fontSize="15"
                                        rowHeight="40"
                                       
                                      >
                       <mx:columns>
                           <mx:DataGridColumn dataField="Name" headerText=" Name"/>
                           <mx:DataGridColumn dataField="Date" headerText="Date"/>    
        
                       </mx:columns>   
                   </mx:DataGrid>

       

       

      This is just a demo, I know I am missing the rest but just to keep the post small. I want ResultListing(ArrayCollection) or basically anything to pass to my List component. I am not sure if I am missing like a Refresh? A update I am just stuck.  What do I need to do on the Search component and List component to be able to pass data between them I do not want a pop up because it raises the programs memory to 700 megs.

        • 1. Re: Passing ArrayCollection From 1 Component to Another
          Gregory Lafrance Level 6

          You should be able to just pass the array collection as a function parameter, and then add it to the list data provider, or replace the list data provider with the array collection.

           

          To add the AC to the list DP you have to iterate over the AC.

           

          If this post answers your question or helps, please mark it as such.

          • 2. Re: Passing ArrayCollection From 1 Component to Another
            Trojan84 Level 1

            I guess I don't understand passing as a function parameter.

            I know how to pass data toa popup

            public function GenerateMap():void
                {
                   
                     ViewMap = Map(PopUpManager.createPopUp(this, Map, true));
                        ViewMap._mapid = _mapid;
                        ViewMap.list = lists;
                        ViewMap._imageURL = "test.jpg";
                        ViewMap.title = String(exhiblist.getItemAt(0));
                        ViewMap["NextMap"].addEventListener("click", removeMap);
                       
                }      

             

             

             

            But what would I do for the component?

             

            I tried doing in the Search

             

            [Bindable]
                        private var PassingList:List;

             

             

            then in a function

             

            set  PassingList.goAC = ListArray;

             

            But when I go to the List component

             

            and do this

             

              [Bindable]
                        public var goAC :ArrayCollection = new ArrayCollection;

             

             

             

            <mx:DataGrid     id="BriefcaseGrid"
                                        allowMultipleSelection="false"
                                        dataProvider="{goAC }"
                                          width="275"
                                          selectable="true"
                                           selectionColor="haloBlue"
                                            variableRowHeight="true"
                                           
                                             fontSize="15"
                                             rowHeight="40"
                                            
                                           >

             

            Nothing Populates is it because I need to force updateit? or does it update automatically? I am just missing the flow I guess of component to component

            • 3. Re: Passing ArrayCollection From 1 Component to Another
              Gregory Lafrance Level 6

              I'm a little confused by your code sample. Maybe a more complete, yet simplified code example.

              • 4. Re: Passing ArrayCollection From 1 Component to Another
                Trojan84 Level 1

                Ok let see if this helps

                 

                I have a project called PassingData

                 

                <?xml version="1.0" encoding="utf-8"?>
                <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
                  layout="horizontal" xmlns:ns1="*" width="1024" height="768" borderColor="#EBEDEF" themeColor="#ffffff" alpha="1.0" viewSourceURL="srcview/index.html"  backgroundGradientAlphas="[1.0, 1.0]" backgroundImage="" backgroundGradientColors="[#000000, #000000]">
                      <mx:ApplicationControlBar id="acb" width="100%" horizontalAlign="center" >
                             
                            <mx:ToggleButtonBar
                                height="75" horizontalAlign="center"
                                dataProvider="TopMenu"
                               />  
                        </mx:ApplicationControlBar>
                    <mx:ViewStack id="TopMenu" width="980" height="100%" creationPolicy="all">
                               <ns1:Search label="Search For" width="100%" height="100%" showEffect="WipeUp" hideEffect="WipeUp"/>
                          <ns1:List label="list" width="100%" height="100%" showEffect="WipeUp" hideEffect="WipeUp"/>
                                        
                          
                        </mx:ViewStack>
                   
                </mx:Application>

                 

                I want to Pass Data From Search

                <?xml version="1.0" encoding="utf-8"?>
                <mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml" width="400" height="300" initialize="myHTTPDetail.send();">
                    <mx:HTTPService id="myHTTPDetail" showBusyCursor="true" method="GET"
                url="grabit.xml"  result="httpResultHandler(event)" >
                </mx:HTTPService>
                <mx:Script>
                <![CDATA[
                    import mx.collections.ArrayCollection;
                   
                //My Imports-------------------------------
                     
                        import mx.rpc.events.ResultEvent;
                      
                //Component Global Vars----------------------
                [Bindable]
                        public var Listings:List;
                   
                        [Bindable] public var MyArray:ArrayCollection = new ArrayCollection();

                 

                private function httpResultHandler(event:ResultEvent):void
                    {   
                        MyArray = event.result.Car.Cars;

                        Listings.Lists = MyArray;
                    }

                 

                ]]>
                </mx:Script>

                 


                </mx:Canvas>

                 

                To List

                <?xml version="1.0" encoding="utf-8"?>
                <mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml" width="400" height="300" >
                   
                    <mx:Script>
                <![CDATA[
                    import mx.collections.ArrayCollection;

                 


                        import mx.rpc.events.ResultEvent;
                     
                //Component Global Vars----------------------
                        [Bindable]
                        public var Get:Search;
                [Bindable]
                        public var Lists:ArrayCollection  = new ArrayCollection;

                 


                ]]>
                </mx:Script>
                    <mx:DataGrid     id="BriefcaseGrid"
                                            allowMultipleSelection="false"
                                             dataProvider="{Lists}"
                                              width="275"
                                              selectable="true"
                                               selectionColor="haloBlue"
                                                variableRowHeight="true"
                                               
                                                 fontSize="15"
                                                 rowHeight="40"
                                                
                                               >
                              
                            </mx:DataGrid>
                           
                               
                </mx:Canvas>

                 

                Some how I need to pass MyArray to the next component when i click on the List button in the viewstack.

                 

                Does that help at ??

                • 5. Re: Passing ArrayCollection From 1 Component to Another
                  Gregory Lafrance Level 6

                  In this case you may want to consider using a custom event, because you can define an ArrayCollection to be a property of the custom event, and the component that dispatches the event can pass the ArrayCollection object into the custom event constructor.

                   

                  The object that will make use of the ArrayCollection can listen for the event, and access the ArrayCollection property of the custom event.

                   

                  This link may help get you started:

                   

                  http://www.google.com/search?hl=en&q=flex+3+dispatching+custom+events&aq=1&oq=flex+3+dispa tching&aqi=g2

                  1 person found this helpful