9 Replies Latest reply on Jul 29, 2009 3:32 PM by cyber0897

    Flex 4 viewstack reload question

    cyber0897 Level 1

      hey guys, im having some trouble reloading the viewstack component everytime it is set to visible.

       

      the basic setup i have is

       

                  <s:Panel id="dataPanel" width="840" height="100%" visible="false">
                      <mx:ViewStack id="myViewStack" width="100%" height="100%">
                          <mx:Canvas id="PanelEditor">
                              <PanelEditor:PanelEditor />
                          </mx:Canvas>
                          <mx:Canvas id="SiteEditor">
                              <SiteEditor:SiteEditor initialize="modules.SiteEditor.siteEditor.init()" />
                          </mx:Canvas>
                      </mx:ViewStack>
                  </s:Panel>

       

      as you can see i have multiple componenets attached to my viewstack.

      the problem im having is that once i change the viewstack, it will not call the initialize function ever again after the first load.

       

      the way i have my code set up is, first all the websites are populated in one datagrid, once an item is clicked on that datagrid, the list of all the modules is populated... (modules = "paneleditor", and "siteeditor").

      once someone clicks on the modules i need to call the initialize function on both everytime for each website. to refesh the data in teh text fields.

       

      please let me know if this dosent make sence.

       

      inside the 'SiteEditor' component i have multiple text fields, and i need to reload these text fields everytime i change the main

       

      this is the function that is called once the modules item is clicked

       

                      public function updateStack():void{
                          selectedSite = siteSelected.selectedItem.id;
                          selectedModule = pram.selectedItem.detailPanel;
                          if(Container(myViewStack.getChildByName(selectedModule)) != null){
                              myViewStack.selectedChild = Container(myViewStack.getChildByName(selectedModule));
                             
                          }
                          else
                              Alert.show(selectedModule + " cannot be found");
                      }

       

       

       

      please let me know if anyone knows how to refewsh the data in those components or call the initialize function evertime.

       

      thank soo much!! i really appretiate it!!

        • 1. Re: Flex 4 viewstack reload question
          cyber0897 Level 1

          soo... does anyone have any ideas???

           

          thanks again in advance guys!!

          • 2. Re: Flex 4 viewstack reload question
            Flex harUI Adobe Employee

            Once a 'page' in a viewstack is created, it won't be initialized again.  You can use the "show" event to know it is being shown again.

             

            Alex Harui

            Flex SDK Developer

            Adobe Systems Inc.

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

            • 3. Re: Flex 4 viewstack reload question
              cyber0897 Level 1

              im very very new to flex, how exactly would i use the show event???

              and is there a way i could may be remove the existing viewstack child so when i call on the component the "init()" function is called again?

               

               

              and thank you soo much for the quick reply!!

              • 4. Re: Flex 4 viewstack reload question
                Flex harUI Adobe Employee

                You can remove the child, but that would be inefficient.  Simply add a show attribute to the tag:

                 

                                        <SiteEditor:SiteEditor initialize="modules.SiteEditor.siteEditor.init()" show="modules.SiteEditor.siteEditor.init()" />

                 

                Alex Harui

                Flex SDK Developer

                Adobe Systems Inc.

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

                • 5. Re: Flex 4 viewstack reload question
                  Peter deHaan Level 4

                  Try this:

                   

                  <mx:Canvas id="SiteEditor" show="modules.SiteEditor.siteEditor.init();">
                      <SiteEditor:SiteEditor />
                  </mx:Canvas>

                   

                  Peter

                  1 person found this helpful
                  • 6. Re: Flex 4 viewstack reload question
                    cyber0897 Level 1

                    nope neither suggestions worked... the data never got refreshed or updated.

                     

                    i tried doing

                     

                                        <mx:Canvas id="SiteEditor" show="modules.SiteEditor.siteEditor.init()">
                                            <SiteEditor:SiteEditor />
                                        </mx:Canvas>

                     

                    and

                     

                                        <mx:Canvas id="SiteEditor">
                                            <SiteEditor:SiteEditor  show="modules.SiteEditor.siteEditor.init()" initialize="modules.SiteEditor.siteEditor.init()" />
                                        </mx:Canvas>

                    • 7. Re: Flex 4 viewstack reload question
                      Peter deHaan Level 4

                      I tested with the following code which updated my button label every time I changed the viewstack:

                       

                      <?xml version="1.0" encoding="utf-8"?> 
                      <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 
                                     xmlns:s="library://ns.adobe.com/flex/spark" 
                                     xmlns:mx="library://ns.adobe.com/flex/halo">
                          <s:HGroup>
                              <s:Button click="myViewStack.selectedIndex = 0;" />
                              <s:Button click="myViewStack.selectedIndex = 1;" />
                          </s:HGroup>
                          
                          <s:Panel id="dataPanel" width="840" height="100" y="100">
                              <mx:ViewStack id="myViewStack" width="100%" height="100%">
                                  <mx:Canvas id="PanelEditor">
                                      <s:Button id="btn1" label="Button #1" />
                                  </mx:Canvas>
                                  <mx:Canvas id="SiteEditor" show="btn2.label = new Date().toTimeString();">
                                      <s:Button id="btn2" label="Button #2" />
                                  </mx:Canvas>
                              </mx:ViewStack>
                          </s:Panel>
                      </s:Application>
                      

                       

                      Peter

                      1 person found this helpful
                      • 8. Re: Flex 4 viewstack reload question
                        cyber0897 Level 1

                        oh wow that actually worked like a charm!! the reason it seemed as if it wasnt working is because i didnt change the modules... i just clicked on a different site in the main data grid, and then the site editor in the module section. The viewstack children never actually went to invisible.

                         

                        is there a way i can have the viewstack children go to invisible when i click on a different datagrid item?

                         

                        what ive tried is inside the datagrid itemclick property i added: myViewStack.visible = false on the main sites list datagrid, and myViewStack.visible = true in the modules datagrid.

                         

                        but unfortunately that did not work.

                        • 9. Re: Flex 4 viewstack reload question
                          cyber0897 Level 1

                          never mind actually i got it working!!

                           

                          thank you sooo much guys!!! i really appretiate all your help!!!

                           

                           

                          i just ended up doing the following code:

                                              <mx:Canvas id="SiteEditor" hide="modules.SiteEditor.siteEditor.init()" show="modules.SiteEditor.siteEditor.init()">
                                                  <SiteEditor:SiteEditor />
                                              </mx:Canvas>

                           

                          i used the hide so when i click away from this, it will update the next one right away...

                           

                           

                          again thanks guys!!