7 Replies Latest reply on Mar 10, 2009 3:08 PM by robbyk87

    Multiple While Loop Problem..

    robbyk87 Level 1
      Hi,

      Got a couple of while loops which dynamically number some fields in an accordion - however only one of them works at a time e.g. I click Poems and it displays the correct values next to the fields but if I click another accordion tab the values are not passed - I dont think the while loop is even executed - can I only do one while loop in a function?

      Any help much appreciated :)

        • 1. Re: Multiple While Loop Problem..
          Ansury Level 3
          There's no such silly limitation on while loops. ^_^

          Is this within a container within the accordion? You may need to describe what you are doing a little further or post a more complete example. Variables are local to the individual component they are declared within, they're not globally accessible anywhere.
          • 2. Re: Multiple While Loop Problem..
            robbyk87 Level 1
            hmmm well, as I said one of them works fine the other doesnt - they are both within an accordion container on the main page.

            So surely if the poOther.text gets changed - surely if using exactly the same method on a while loop further down the page should change the other label reOther.text

            they are identical except for the slight varaition re/po etc. and if i comment one out - the other one which didn't work then works!

            Been driving me crazy honestly - thanks for the quick reply btw but limitation is the only thing i can think of atm.
            • 3. Multiple While Loop Problem..
              robbyk87 Level 1
              if it will help here is basically the full code - as you can see (to my eyes anyway) they are more or less identical except id values etc. Each .text refers to a label .text value on the main stage - this code is in a result handler - php and mysql passes fine - but as I said it only computes one of the while loops - or compiles both but only chooses to change the .text labels in one of the loops:

              Hope this helps understand better - any ideas guys? Thanks!

              BTW!!!

              Sorry about the a<storyNum - I undid too far before I copied this should be poemNum and I have changed it to that but it does not work!
              • 4. Re: Multiple While Loop Problem..
                Ansury Level 3
                I wish I had the time today to look at this closer but I can only glance over things. I'm guessing that your problem lies somewhere else in your application. Are you sure that poemNum and reviewNum are the values you expect them to be? Have you tried using the debugger to see which condition that you expect to be true is evaluating differently? That's probably the quickest way to figure this out.

                I'm not sure why commenting one out would fix the other. I'm also not sure what the accordion control has to do with it (that's why I ask for more context). Perhaps you have a glitch in your mxml that is causing confusion?
                • 5. Re: Multiple While Loop Problem..
                  robbyk87 Level 1
                  Hi Ansur thanks for taking the time to look at it - perhaps if I gave you the beta testing link for the site?

                  http://robkent.co.uk/wab/

                  As you can see - on the right there are numeric values attached to stories (16) and Poems (2) and when you open the accordion you can see that in stories the count is correct next to each subgenre.

                  But in poems it is not displaying at all...

                  mxml is very simple for it - just each label has an id value (which the id.text changes the label text in the code).

                  Basically:

                  <mx:VBox label="STORIES" id="storiesAcc" icon="{storiesIcon}">
                  <mx:VBox id="storySub" horizontalAlign="center" width="180" height="100%" paddingTop="10">
                  <mx:Label text="" id="stOther" fontSize="10"/>
                  <mx:Label text="Love" id="stLove" FontSize="10"/>
                  </mx:VBox>
                  </mx:VBox>

                  <mx:VBox label="POEMS" id="poemsAcc" icon="{poemsIcon}">
                  <mx:VBox id="poemSub" horizontalAlign="center" width="180" height="100%" paddingTop="10">
                  <mx:Label text="Other" id="poOther" fontSize="10"/>
                  <mx:Label text="Love" id="poLove" fontSize="10"/>

                  </mx:VBox>
                  </mx:VBox>
                  • 6. Multiple While Loop Problem..
                    Ansury Level 3
                    :( Requires Flash 10 and I only have 9 on this workstation.

                    But - IIRC accordions don't create instances of every sub container when the accordion is created, only the first "visible" one. So if the first VBox section is for the first accordion "tab", the second wouldn't have been created yet. Still not 100% positive (don't have a clear picture of what's going on) but this might be something to look into.

                    A quick way to verify that this is the issue would be to set the creationPolicy on the accordion to "all". But it's most likely a bad idea to leave it like that (poor performance), I'd only do it to troubleshoot, and then find a better solution. ..Assuming that's even the issue.

                    But I would definitely walk through the code in the debugger if that's not it (I would imagine an error popping up for you if it's the problem above). A function isn't just going to return for no reason, it may be skipping either the while or the conditions inside.
                    • 7. Re: Multiple While Loop Problem..
                      robbyk87 Level 1
                      Excellent suggestion Ansury, unfortunately I dont fancy slowing down the website anymore than it is lol.

                      But your suggestion did lead me onto to an interesting conclusion - I wrapped my while loops in an if (accordion.selectedIndex == 3){ }.

                      This calls the while loop if the selected accordion element is the right one - takes a tiny while for new values to be updated (as the change event for the accordion is set to an httpService) but it seems to work nicely!

                      Thanks for chatting me through it lol - and those admin controls - like being back at uni lol

                      Take Care,

                      Rob