3 Replies Latest reply on May 28, 2008 1:23 PM by Bryan Dresselhaus

    nested loop problem

    nif
      hi there,

      i have an odd situation with a nested loop where it is exiting the loops if i make reference to the children found in an upper level loop.... not though if i Alert the variables.
      this probably doesn't make much sense, so i have pasted the code below... i've left in the commented stuff so that you can see what i have tried.
      just a quick note... i am using this function to loop through a container and find the container's children... and then looping through the children of those children.... and hopefully the children of those children after that.

      if you run the code as is you should get a full relay of the containers and their children in Alerts.
      however, if you unhide one of the lines which states that it causes a crash, then you'll see that the loop only runs once and then exits.

      any ideas would be so appreciated right now! i have a sticky deadline and am frustrated just staring at this code trying to figure out where i am going wrong.

      thanks a mil',
      nikki
        • 1. Re: nested loop problem
          Bryan Dresselhaus
          Your sub loop fails because not all UIComponents have a getChildren method. Only UIComponents that are containers have getChildren method.

          Secondly, your logic won't pick up all the children of the containers. What if you have nested containers? The nested container's children won't be picked up in the loop.

          I'll write out a loop for you shortly that will do what you need.
          • 2. Re: nested loop problem
            nif Level 1
            hi bryan,

            thanks a mil' for that! i hadn't even thought of it.

            re: the nested containers... i have a fairly static setup and am only looking for containers on 3 levels that contain a function i do a check for and if it exists i run it. the function will only exist in the main and sub and then possibly sub components... the mxml is below... really only targetting the custom components that i am calling... the viewstack is what causes me to have to check one level deeper to get to the custom components in there.

            thanks again! i would have sat here all night trying to figure that one out!
            nikki

            <?xml version="1.0" encoding="utf-8"?>
            <mx:TabNavigator xmlns:mx=" http://www.adobe.com/2006/mxml" xmlns:rp="Reports.*" width="100%" height="100%">
            <mx:Style source="site.css" />
            <mx:Script source="../resetting.as" />
            <mx:Canvas id="Reports_1" label="Agent Results" width="100%" height="100%">
            <mx:Image source="assets/image_view_reports_agent_results.jpg" bottom="0"/>
            <rp:Report_1_1_Filter id="Report_1_1_Filter" x="11"/>
            <rp:Report_1_1 id="Report_1_1_Listing" x="278" y="1"/>
            </mx:Canvas>
            <mx:Canvas id="Reports_2" label="Agent Breakdown" width="100%" height="100%">
            <mx:Image source="assets/image_view_reports_agent_breakdown.jpg" bottom="0"/>
            <rp:Report_2_Filter id="Report_2_Filter" x="11" />
            <mx:ViewStack id="Report_2_Listing" x="278" y="1" width="100%">
            <rp:Report_2_1 id="Report_2_1_Listing" width="100%"/>
            <rp:Report_2_1 id="Report_2_2_Listing" width="100%" />
            <rp:Report_2_1 id="Report_2_3_Listing" width="100%" />
            </mx:ViewStack>
            </mx:Canvas>
            <mx:Canvas id="Reports_3" label="Performance Ratings" width="100%" height="100%">
            <mx:Image source="assets/image_view_reports_performance_rating.jpg" bottom="0"/>
            <rp:Report_3_Filter id="Report_3_Filter" x="11"/>
            <rp:Report_3_1 id="Report_3_1_Listing" x="278" y="1"/>
            </mx:Canvas>
            </mx:TabNavigator>
            • 3. Re: nested loop problem
              Bryan Dresselhaus Level 1
              See if this works for you. Make a class called Utils.as with the following code attached below. Make sure you update the package keyword. You pass it a container object, which can be a module, application, canvas...ect. It will recursively navigate the containers and identify the children.