14 Replies Latest reply on May 8, 2015 6:32 PM by kglad

    AS3/AIR - for loop being skipped but rest of function runs

    sawmangs4 Level 1

      This has stumped me. It is either something really stupid on my part or Flash's part. Here goes:

       

      I have a function that simply accepts an array of movieclip references, runs a loop to add them to a sprite container, then gives the container a background color. It works perfectly the first time. Now, when the program comes back to that function again it completely skips the loop but still adds the background color. here is  the function:

       

      public function prepareContainer(sections):Sprite

        {

         trace("prepareContainer called!");

         trace("sections is "+sections);

         containerClips.splice(0,containerClips.length);

         trace("containerClips.length is "+containerClips.length);

         for(var rs:int = 0; rs < sections.length; rs++)

         {

          trace("sections["+rs+"] is "+sections[rs]);

         }

         var w:Number = 0;

         var l:Number = 0;

         for(var sx:int = 0; sx < sections.length; sx++)

         {

          trace("sx is "+sx);

          var section = sections[sx];

          if(sx > 0)

          {

           section.y = sections[sx-1].y + sections[sx-1].height;

           w = section.width;

           l = l + section.height;

          }

          container.addChild(section);

         }

         container.graphics.beginFill(0xfafafa); // Just for background color in container.

         container.graphics.drawRect(0,0,w,l);

         container.graphics.endFill();

         containerClips = sections;

         for(var p:int = 0; p < containerClips.length; p++)

         {

          trace("containerClips["+p+"] is "+containerClips[p]);

         }

         return container;

        }

       

      You can also see that I have traces in the function to trace the contents and length of the incoming array.

      This is the trace from the first time through:

       

      prepareContainer called!

      sections.length is [object ViewPrevTranClosed_AEM],[object medicareHead_AEM],[object NAMEsubscriberSection_AEM],[object SearchInformationSection_AEM]

      containerClips.length is 0

      sections[0] is [object ViewPrevTranClosed_AEM]

      sections[1] is [object medicareHead_AEM]

      sections[2] is [object NAMEsubscriberSection_AEM]

      sections[3] is [object SearchInformationSection_AEM]

      sx is 0

      sx is 1

      sx is 2

      sx is 3

      containerClips[0] is [object ViewPrevTranClosed_AEM]

      containerClips[1] is [object medicareHead_AEM]

      containerClips[2] is [object NAMEsubscriberSection_AEM]

      containerClips[3] is [object SearchInformationSection_AEM]

      ============================================

       

      As you can see, the traces in the loops ran just fine and the result is as expected. The container is filled with the movieclips. However, on the next time through the result is only the background color and none of the movieclips are added to the container. The following trace also shows that the loops did not run even though the array is populated and there are no conditionals that stop the loops. Here is the trace:

       

      prepareContainer called!

      sections.length is [object ViewPrevTranClosed_AEM],[object medicareHead_AEM],[object NAMEsubscriberSection_AEM],[object SearchInformationSection_AEM]

      containerClips.length is 0

       

      Any ideas as to what is causing this?

        • 1. Re: AS3/AIR - for loop being skipped but rest of function runs
          kglad Adobe Community Professional & MVP

          neither of those trace sequences is expected from the prepareContainer() you showed.  something else is generating that trace output.

           

          ie, you're not calling the prepareContainer() you showed so the problem occurs prior to anything you showed possibly even in a same named class file saved in a superdirectory of the one that contains the file with the shown code.

          • 2. Re: AS3/AIR - for loop being skipped but rest of function runs
            sawmangs4 Level 1

            I Apologize. You were probably thrown off by the trace directly under the "prepareContainer called!" trace. In the function shown it says: trace("sections is "+sections);

             

            but the resulting trace says: sections.length is [object ViewPrevTranClosed_AEM],[object medicareHead_AEM],[object NAMEsubscriberSection_AEM],[object SearchInformationSection_AEM]

             

            I deleted the .length part from the function after I pasted it into the forum. However, the trace sequence's are from that function.

             

            Does that make sense?

            • 3. Re: AS3/AIR - for loop being skipped but rest of function runs
              kglad Adobe Community Professional & MVP

              not to me, but maybe someone else can make sense of your posts.

              • 4. Re: AS3/AIR - for loop being skipped but rest of function runs
                Colin Holgate MVP & Adobe Community Professional

                I understood the post, and guessed that the ".length" part had been removed before the trace statements were made. But, with the script as it's shown here, the problem couldn't possibly happen. Could you post the file somewhere?

                 

                Why do you use this:

                 

                containerClips.splice(0,containerClips.length);

                 

                instead of:

                 

                containerClips = [];

                 

                ?

                • 5. Re: AS3/AIR - for loop being skipped but rest of function runs
                  sawmangs4 Level 1

                  The containerClips.splice(0,containerClips.length); is used because read that the splice method was faster/better.

                   

                  I guess I'll post the class here. Be aware there is a lot of commented out code right now from testing different ways of writing the code. Any way, here is the whole class:

                   

                  package
                  {
                  // ATCBrowser 1.0

                  import flash.display.*;
                  import flash.desktop.*;
                  import flash.events.*;
                  import fl.events.*;
                  import flash.html.HTMLLoader;
                  import flash.net.*;
                  import fl.controls.*;
                  import fl.containers.ScrollPane;
                  import fl.managers.*;
                  import flash.filesystem.*;
                  import flash.geom.Rectangle;
                  import fl.transitions.Tween;
                  import fl.transitions.easing.*;
                  import flash.filters.DropShadowFilter;
                  import flash.text.*;

                  public class ATCBrowser extends MovieClip
                  {
                    public var back_btn;
                    public var forward_btn;
                    //public var go_btn;
                    public var address_txt:TextField;
                    public var downTween:Tween;
                    public var upTween:Tween;
                    public var backGround:MainBackingMC = new MainBackingMC;
                    public var container:Sprite = new Sprite();
                    public var newtitle:String;
                    public var scrollArea:ScrollPane = new ScrollPane();
                    public var containerClips:Array = new Array();
                    public var thisWin:NativeWindow;
                    public var file:File = File.applicationStorageDirectory;
                    public var historyManager:BrowserHistoryManager = new BrowserHistoryManager();
                    public var CURRENTHEADER:MovieClip;
                    public var BottomGreen:BottomCenterGreen = new BottomCenterGreen;
                    public var currentPageSections:Array = new Array();
                    public var mc; // Used loading and browser history functions.
                    public var listing;  // Used loading and browser history functions.
                    public var swfasset;
                   
                    //////////////////////////////////////////////////////////// AWSplash MovieClip VARS //////////////////////////////////////////////////////////////
                   
                    //============================================== LoginPage =======================================================================================
                    public var loginpage:LoginPage = new LoginPage;
                    // =========================================== Choose Facility Page ==============================================================================
                    public var choosePage:ChoosePage = new ChoosePage;
                    // ============================================= Adhoc Home Page =================================================================================
                    public var Home:AdhocHomePage = new AdhocHomePage;
                    // ============================================= Adhoc Medicare Form Page ========================================================================
                    public var MedicareForm:AEMFORM = new AEMFORM;
                    // ============================================= Adhoc Emdeon Address Verification Page ==========================================================
                    public var AddressVerificationForm:AEAV = new AEAV;
                    // ============================================= Adhoc Emdeon Medicare Response Page =============================================================
                    public var AMRresponse=AMR.getAMR();
                    public var PrevTransbtn = AMRresponse.sect2_ViewPrevTranClosed_AEM.PrevTransbtn;
                    public var VPTSopenBtn = AMRresponse.sect2_ViewPrevTranOpen_AEM.VPTSopenBtn;
                    public var sect2_ViewPrevTranClosed_AEM=AMR.getAMR().sect2_ViewPrevTranClosed_AEM;
                    public var sect2_ViewPrevTranOpen_AEM=AMR.getAMR().sect2_ViewPrevTranOpen_AEM;
                    // ============================================= Adhoc Emdeon Address Verification Response Page =================================================
                    public var AVRresponse:AVR = new AVR;
                   
                    public function ATCBrowser()
                    {
                     addEventListener(Event.ADDED_TO_STAGE, initBrowser);
                    } // // ----------------------------------------------------------------------------------------- ---------- End constructor function ATCBrowser().
                   
                    public function initBrowser(e:Event = null):void
                    {
                     trace("ATCBrowser running! "+this.name);
                     container.useHandCursor = false;
                     thisWin = this.stage.nativeWindow;
                     back_btn.tabEnabled = false;
                     forward_btn.tabEnabled = false;
                     address_txt.tabEnabled = false;
                     backGround.x = -10;
                     backGround.y = 45;
                     addChild(backGround);
                     scrollArea.addEventListener(ScrollEvent.SCROLL, scrolling); // Not currently in use.
                     if(thisWin.active)
                     {
                      CURRENTHEADER = loginpage.pageHeader;
                      insertSWFAssets(loginpage);
                     }
                    
                     loginpage.title = "//assistant.emdeon/login";
                     newtitle = loginpage.title;
                     loginpage.loginbtn.addEventListener(MouseEvent.CLICK, clickedLoginPageloginbtn);
                     choosePage.title = "//assistant.emdeon/choose-provider"
                     choosePage.chooseLocationAcceptBtn.addEventListener(MouseEvent.CLICK, clickedLocationAccept);
                    
                     MedicareForm.PDDBucket_MC.EAVBtn.addEventListener(MouseEvent.CLICK, clickedAV_btn);
                     MedicareForm.SubmitSectionMC.subFlasher.addEventListener(MouseEvent.CLICK, clickedMedicaresubFlasher);
                     PrevTransbtn.addEventListener(MouseEvent.CLICK, clickedSectionButton);
                     VPTSopenBtn.addEventListener(MouseEvent.CLICK, clickedSectionButton);
                    
                     AddressVerificationForm.subsecflash.addEventListener(MouseEvent.CLICK, clickedsubsecflash);
                    
                    } // ----------------------------------------------------------------------------------------- ----------------- End public function initBrowser().
                   
                    //////////////////////////////////////////////////////// Login Page Page Functions //////////////////////////////////////////////////////////////
                   
                    public function clickedLoginPageloginbtn(e:MouseEvent = null):void
                    {
                     insertSWFAssets(choosePage);
                    } // ----------------------------------------------------------------------------------------- ---------- End function clickedLoginPageloginbtn().
                   
                    //////////////////////////////////////////////////////// Choose Facility Page Functions ////////////////////////////////////////////////////////
                   
                    function clickedLocationAccept(e:MouseEvent = null):void
                    {
                     // chooseLocationAcceptBtn physically located in choosepage_mc MovieClip @ AWSplash.fla
                     trace("clickedLocationAccept clicked!");
                     insertSWFAssets(Home);
                    } // ----------------------------------------------------------------------------------------- ------- End public function clickedLocationAccept().
                   
                    ////////////////////////////////////////////////////////////// Home Page Functions //////////////////////////////////////////////////////////////
                    public function clickedEligibility(e:MouseEvent = null):void
                    {
                     insertSWFAssets(MedicareForm);
                    } // ----------------------------------------------------------------------------------------- --------- End public function clickedEligibility().
                   
                    public function clickedAV_btn(e:MouseEvent = null):void
                    {
                     insertSWFAssets(AddressVerificationForm);
                    } // ----------------------------------------------------------------------------------------- -------------- End public function clickedAV_btn().
                   
                    //////////////////////////////////////////////////////////// Medicare Form Page Functions ///////////////////////////////////////////////////////
                   
                    public function clickedMedicaresubFlasher(e:MouseEvent = null):void
                    {
                     insertSWFAssets(AMRresponse,AMRresponse.initialLoadArray);
                    } // ----------------------------------------------------------------------------------------- -- End public function clickedMedicaresubFlasher().
                   
                    public function clickedSectionButton(e:MouseEvent = null):void
                    {
                     //sect2_ViewPrevTranClosed_AEM
                     trace("Clicked e.currentTarget "+e.target.name);
                     switch(e.target)
                     {
                      case PrevTransbtn:
                       openCloseSection(sect2_ViewPrevTranClosed_AEM,sect2_ViewPrevTranOpen_AEM);
                       break;
                      case VPTSopenBtn:
                       openCloseSection(sect2_ViewPrevTranOpen_AEM,sect2_ViewPrevTranClosed_AEM);
                       break;
                     }
                    
                    } // ----------------------------------------------------------------------------------------- -------- End public function clickedPrevTransbtn().
                   
                    //////////////////////////////////////////////////////////// Address Verification Form Page Functions //////////////////////////////////////////
                   
                    public function clickedsubsecflash(e:MouseEvent = null):void
                    {
                     insertSWFAssets(AVRresponse);
                    } // ----------------------------------------------------------------------------------------- --------- End public function clickedsubsecflash().
                   
                    //////////////////////////////////////////////////////// BROWSER Functions ////////////////////////////////////////////////////////////////////
                   
                    public function insertSections(Page:MovieClip, sectionList:Array)
                    {
                     //======================================================================================= ==
                     //
                     // This function loads pages that rquire multiple sections
                     trace("insertSections called!");
                     container.removeChildren(); // Removing any children so new children can be added in the function prepareContainer().
                     scrollArea.source = null;
                     Page != null ? newtitle = Page.title : newtitle = ""; // newtitle is string used in the broswer address bar.
                     if(Page == null)
                     {
                      updateBrowserButtons();
                      return;
                     }
                     else
                     {
                      if(contains(CURRENTHEADER))
                      {
                       CURRENTHEADER.filters = [];
                       removeChild(getChildByName(CURRENTHEADER.name));
                      }
                      CURRENTHEADER = Page.pageHeader; // determines which header to add to the stage.
                      CURRENTHEADER.headtype = Page.headtype;
                      if(CURRENTHEADER.headtype != "introHeader")//LoginHeader
                      {
                       setupBucketDropshadow(CURRENTHEADER);
                      }
                      prepareContainer(sectionList);/////////////////////////////////////////////////////////// ////
                      newtitle = Page.title;
                      addChild(container);
                      if(contains(scrollArea))
                      {
                       scrollArea.source = container;// source needs to be container with swfasset inside.
                       scrollArea.update();
                       address_txt.text = newtitle;
                       ifNotcontainsCURRENTHEADER();//////////////////////////////////////////////////////
                       if(container.height > thisWin.height - scrollArea.y)
                       {
                        scrollArea.setSize(1500, thisWin.height - scrollArea.y - 50);
                       }
                       else
                       {
                        scrollArea.setSize(1500, container.height);
                       }
                      }
                      else
                      {
                       scrollArea.addEventListener(Event.INIT, initscrollArea);
                       scrollArea.source = container;
                       addChild(scrollArea);
                      }
                      historyManager.receiveInfo(Page,sectionList);
                     }
                     updateBrowserButtons();
                    } // ----------------------------------------------------------------------------------------- ------------ End public function insertSections().
                   
                    // This function loads a single MovieClip into the scrollArea and its header assets.
                    public function insertSWFAssets(...ARGS)
                    {
                     trace("insertSWFAssets called!");
                     trace("ARGS.length is "+ARGS.length);
                     if(container.numChildren > 0)
                     {
                      container.removeChildren();
                     }
                     swfasset = ARGS[0];
                     if("mc" in swfasset)
                     {
                      trace("if(mc in swfasset)");
                      trace("ARGS[0].mc is "+ARGS[0].mc);
                      trace("ARGS[0].listing is "+ARGS[0].listing);
                      insertSections(ARGS[0].mc,ARGS[0].listing);
                      return;
                     }
                     if(ARGS.length > 1)
                     {
                      trace("IF ARGS.length is "+ARGS.length);
                      insertSections(ARGS[0],ARGS[1]);
                      return;
                     }
                     trace("1 ============================================");
                     var activeWin = NativeApplication.nativeApplication.activeWindow;
                     container.removeChildren(); // Removing any children so new children can be added in the function prepareContainer().
                     swfasset != null ? newtitle = swfasset.title : newtitle = ""; // newtitle is string used in the broswer address bar.
                     if(swfasset == null)
                     {
                      updateBrowserButtons();
                      return;
                     }
                     else
                     {
                      if(contains(CURRENTHEADER))
                      {
                       CURRENTHEADER.filters = [];
                       removeChild(getChildByName(CURRENTHEADER.name));
                      }
                      CURRENTHEADER = swfasset.pageHeader; // determines which header to add to the stage.
                      if(CURRENTHEADER.headtype != "introHeader")
                      {
                       setupBucketDropshadow(CURRENTHEADER);
                      }
                      newtitle = swfasset.title;
                      container.addChild(swfasset);
                      addChild(container);
                      if(contains(scrollArea))
                      {
                       scrollArea.source = container;//swfasset; // source needs to be container with swfasset inside.
                       scrollArea.update();
                       address_txt.text = newtitle;
                       ifNotcontainsCURRENTHEADER();//////////////////////////////////////////////////////
                       if(container.height > thisWin.height - scrollArea.y)
                       {
                        scrollArea.setSize(1500, thisWin.height - scrollArea.y - 50);
                       }
                       else
                       {
                        scrollArea.setSize(1500, container.height);
                       }
                      }
                      else
                      {
                       scrollArea.addEventListener(Event.INIT, initscrollArea);
                       scrollArea.source = container;
                       addChild(scrollArea);
                      }
                      historyManager.receiveInfo(swfasset);
                     }
                     updateBrowserButtons();
                    } // ----------------------------------------------------------------------------------------- -------------------- End function insertSWFAssets().
                   
                    public function initscrollArea(e:Event = null):void
                    {
                     trace("============================================");
                     trace("initscrollArea called! "+scrollArea.source);
                     scrollArea.scrollDrag = false;
                     scrollArea.update();
                     thisWin.addEventListener(NativeWindowBoundsEvent.RESIZE, windowResized);
                    } // ----------------------------------------------------------------------------------------- ------------------- End public function swfloaded().
                   
                    public function clickedBackBtn(e:MouseEvent = null):void
                    {
                     trace("Clicked Back!");
                     insertSWFAssets(historyManager.openHistoricalPageBack());
                    } // ----------------------------------------------------------------------------------------- -------------- End public function clickedBackBtn().
                   
                    public function clickedForwardBtn(e:MouseEvent = null):void
                    {
                     trace("Clicked Forward!");
                     insertSWFAssets(historyManager.openHistoricalPageForward());
                    } // ----------------------------------------------------------------------------------------- ----------- End public function clickedForwardBtn().
                   
                    public function updateBrowserButtons()
                    {
                     switch(historyManager.checkHistory())
                     {
                      case "BACK":
                       back_btn.mouseEnabled = true;
                       forward_btn.mouseEnabled = false;
                       back_btn.enabled = true;
                       forward_btn.enabled = false;
                       break;
                      case "FORWARD":
                       back_btn.mouseEnabled = false;
                       forward_btn.mouseEnabled = true;
                       back_btn.enabled = false;
                       forward_btn.enabled = true;
                       break;
                      case "BOTH":
                       back_btn.mouseEnabled = true;
                       forward_btn.mouseEnabled = true;
                       back_btn.enabled = true;
                       forward_btn.enabled = true;
                       break;
                      case "NONE":
                       back_btn.mouseEnabled = false;
                       forward_btn.mouseEnabled = false;
                       back_btn.enabled = false;
                       forward_btn.enabled = false;
                       break;
                     }
                     back_btn.mouseEnabled = false ? back_btn.alpha = 0.5 : back_btn.alpha = 1;
                     back_btn.enabled ? back_btn.addEventListener(MouseEvent.CLICK, clickedBackBtn) : back_btn.removeEventListener(MouseEvent.CLICK, clickedBackBtn);
                     forward_btn.enabled ? forward_btn.addEventListener(MouseEvent.CLICK, clickedForwardBtn) : forward_btn.removeEventListener(MouseEvent.CLICK, clickedForwardBtn);
                    } // ----------------------------------------------------------------------------------------- ------- End public function updateBrowserButtons().
                   
                    ////////////////////////////////////////////////////////////// UTILITY FUNCTIONS ///////////////////////////////////////////////////////////////
                   
                    public function windowResized(e:NativeWindowBoundsEvent = null):void
                    {
                     trace("============================================");
                     trace("Window Resized!");
                     backGround.width = thisWin.width;   // Sets up the background image on the browser stage.
                     backGround.height = thisWin.height - 45; // ==================================================
                     if(!contains(CURRENTHEADER))
                     {
                      ifNotcontainsCURRENTHEADER();
                     }
                     address_txt.text = newtitle;
                     addChild(scrollArea);
                     scrollArea.focusManager.deactivate();
                     stage.focus = null;
                    } // ----------------------------------------------------------------------------------------- --------------- End public function windowResized().
                   
                    public function ifNotcontainsCURRENTHEADER()
                    {
                     trace("============================================");
                     trace("ifNotcontainsCURRENTHEADER called!");
                     CURRENTHEADER.x = stage.stageWidth / 2 - CURRENTHEADER.width / 2 - 45;
                     CURRENTHEADER.y = 45;
                     addChild(CURRENTHEADER);
                     var bounds:Rectangle = stage.getBounds(stage);
                     scrollArea.x = stage.stageWidth/2 - scrollArea.content.width/2 - 45;
                     scrollArea.y = CURRENTHEADER.y + CURRENTHEADER.height - 1;
                     if(scrollArea.source.height > thisWin.height - scrollArea.y)
                     {
                      // This sets up the scrollArea if the page being loaded is taller than the native window height.
                      scrollArea.setSize(1500, thisWin.height - scrollArea.y - 50);
                     }
                     else
                     {
                      // This sets up the scrollArea if the page being loaded is shorter than the native window height.
                      scrollArea.setSize(1500, container.height);
                     }
                    } // ----------------------------------------------------------------------------------------- -- End public function ifNotcontainsCURRENTHEADER().
                   
                    public function prepareContainer(sections):Sprite
                    {
                     trace("1 prepareContainer called!");
                     trace("sections[1] is "+sections[1]);
                     trace("sections.length is "+sections.length);
                    
                     if(containerClips.length > 0)
                     {
                      containerClips.splice(0,containerClips.length);
                     }
                     trace("containerClips.length is "+containerClips.length);
                     for(var rs:int = 0; rs < sections.length; rs++)
                     {
                      trace("sections["+rs+"] is "+sections[rs]);
                     }
                     var w:Number = 0;
                     var l:Number = 0;
                     if(container.numChildren == 0)
                     {
                      trace("container.numChildren is "+container.numChildren);
                      for(var sx:int = 0; sx < sections.length; sx++)
                      {
                       trace("sx is "+sx);
                       var section = sections[sx];
                       if(sx > 0)
                       {
                        section.y = sections[sx-1].y + sections[sx-1].height;
                        w = section.width;
                        l = l + section.height;
                       }
                       container.addChild(section);
                      }
                     }
                     container.graphics.beginFill(0xfafafa); // Just for background color in container.
                     container.graphics.drawRect(0,0,w,l);
                     container.graphics.endFill();
                     containerClips = sections;
                     for(var p:int = 0; p < containerClips.length; p++)
                     {
                      trace("containerClips["+p+"] is "+containerClips[p]);
                     }
                    
                     return container;
                    } // ----------------------------------------------------------------------------------------- ----------- End public function prepareContainer().
                   
                    public function openCloseSection(ClosingSection:MovieClip,OpeningSection:MovieClip)
                    {
                     trace("OpenCloseSection called");
                     trace("OpeningSection is "+OpeningSection);
                     for(var i:int = 0; i < containerClips.length; i++)
                     {
                      if(ClosingSection == containerClips[i])
                      {
                       containerClips[i] = OpeningSection;
                      }
                     }
                     for(var p:int = 0; p < containerClips.length; p++)
                     {
                      trace(containerClips[p]);
                     }
                     //container.removeChildren();
                     refillContainer();
                    } // ----------------------------------------------------------------------------------------- --------- End public function openCloseSection().
                   
                    public function refillContainer()
                    {
                     trace("refillContainer called!");
                     container.removeChildren();
                     var w:Number = 0;
                     var l:Number = 0;
                     for(var i:int = 0; i < containerClips.length; i++)
                     {
                      var newSection = containerClips[i];
                      if(i > 0)
                      {
                       newSection.y = containerClips[i-1].y + containerClips[i-1].height;
                       w = newSection.width;
                       l = l + newSection.height;
                      }
                      container.addChild(newSection as MovieClip);
                     }
                     container.graphics.beginFill(0xfafafa); // Just for background color in container.
                     container.graphics.drawRect(0,0,w,l);
                     container.graphics.endFill();
                     scrollArea.setSize(container.width, container.height);
                    } // ----------------------------------------------------------------------------------------- ----------- End public function refillContainer().
                   
                    public function setupBodyDropshadow(mc)
                    {
                     var dropshadow:DropShadowFilter = new DropShadowFilter();
                     dropshadow.distance = 1;
                     dropshadow.angle = 45;
                     dropshadow.color = 0x333333;
                     dropshadow.alpha = .7;
                     dropshadow.blurX = 4;
                     dropshadow.blurY = 4;
                     dropshadow.strength = .7;
                     dropshadow.quality = 100;
                     dropshadow.inner = false;
                     dropshadow.knockout = false;
                     dropshadow.hideObject = false;

                     mc.filters = new Array(dropshadow);
                    } // ----------------------------------------------------------------------------------------- ------------------------- End setupBodyDropshadow().
                   
                    public function setupBucketDropshadow(mc)
                    {
                     var dropshadow:DropShadowFilter = new DropShadowFilter();
                     dropshadow.distance = 1;
                     dropshadow.angle = 45;
                     dropshadow.color = 0x333333;
                     dropshadow.alpha = .7;
                     dropshadow.blurX = 4;
                     dropshadow.blurY = 4;
                     dropshadow.strength = .7;
                     dropshadow.quality = 100;
                     dropshadow.inner = false;
                     dropshadow.knockout = false;
                     dropshadow.hideObject = false;

                     mc.filters = new Array(dropshadow);
                    } // ----------------------------------------------------------------------------------------- ------------------------- End setupBodyDropshadow().
                   
                    public function setupNavDropshadow(mc)
                    {
                     var dropshadow:DropShadowFilter = new DropShadowFilter();
                     dropshadow.distance = 10;
                     dropshadow.angle = 87;
                     dropshadow.color = 0x333333;
                     dropshadow.alpha = .8;
                     dropshadow.blurX = 9;
                     dropshadow.blurY = 9;
                     dropshadow.strength = 1;
                     dropshadow.quality = 100;
                     dropshadow.inner = false;
                     dropshadow.knockout = false;
                     dropshadow.hideObject = false;

                     mc.filters = new Array(dropshadow);
                    } // ----------------------------------------------------------------------------------------- ------------------------- End setupNavDropshadow().
                   
                    public function scrolling(e:ScrollEvent = null):void
                    {
                     // TODO - unneeded at this time.
                    } // ----------------------------------------------------------------------------------------- ------------------- End public function scrolling().

                  } // ----------------------------------------------------------------------------------------- -------------------------------- End class ATCBrowser{}.

                  } // ----------------------------------------------------------------------------------------- --------------------------------------------- End package{}.

                  • 6. Re: AS3/AIR - for loop being skipped but rest of function runs
                    kglad Adobe Community Professional & MVP

                    that explains why your first post made no sense;  the code that generates your trace output is significantly different from the code you posted in both messages that contain code.

                     

                    now, using the code posted in message 5 (with no changes), what trace output do you see that's unexpected?

                    • 7. Re: AS3/AIR - for loop being skipped but rest of function runs
                      sawmangs4 Level 1

                      Yes, I have been trying to debug so the code looks different now. Anyway, here is the trace from the first time through:

                       

                      1 prepareContainer called!

                      sections[1] is [object medicareHead_AEM]

                      sections.length is 4

                      containerClips.length is 0

                      sections[0] is [object ViewPrevTranClosed_AEM]

                      sections[1] is [object medicareHead_AEM]

                      sections[2] is [object NAMEsubscriberSection_AEM]

                      sections[3] is [object SearchInformationSection_AEM]

                      container.numChildren is 0

                      sx is 0

                      sx is 1

                      sx is 2

                      sx is 3

                      containerClips[0] is [object ViewPrevTranClosed_AEM]

                      containerClips[1] is [object medicareHead_AEM]

                      containerClips[2] is [object NAMEsubscriberSection_AEM]

                      containerClips[3] is [object SearchInformationSection_AEM]

                       

                      Exactly what is expected.

                      Then hit the back button once which reloads the prior movieclip/s and then the forward button which should just reload the container from the supplied array "sections". what gets traced is as follows:

                       

                      1 prepareContainer called!

                      sections[1] is [object medicareHead_AEM]

                      sections.length is 4

                      containerClips.length is 0

                      container.numChildren is 0

                       

                      This trace shows that the array is still intact but the loops just don't run. It does put the background graphics color in.

                       

                      I'm scratching my head on this one. Two days now.

                      • 8. Re: AS3/AIR - for loop being skipped but rest of function runs
                        kglad Adobe Community Professional & MVP

                        what's the relationship between containerClips and sections on that second run-through?

                        • 9. Re: AS3/AIR - for loop being skipped but rest of function runs
                          sawmangs4 Level 1

                          There is none. containerClips is used to refill the container during a completely different operation that only removes one clip, replaces it with another, and then makes sure all the clips are in order. I simply empty it in this function because when the container is completely refilled with new clips, as in this function, it will be ready for the other operation if necessary. So I empty it at the top of the function and then reload it with the fresh clips after the container is filled.

                          • 10. Re: AS3/AIR - for loop being skipped but rest of function runs
                            kglad Adobe Community Professional & MVP

                            then what's the trace output if you replace prepareContainer() with:

                             

                              public function prepareContainer(sections):Sprite

                              {

                               trace("1 prepareContainer called!");

                               trace("sections[1] is "+sections[1]);

                               trace("sections.length is "+sections.length);

                              

                               if(containerClips.length > 0)

                               {

                                containerClips.splice(0,containerClips.length);

                               }

                               trace("containerClips.length is "+containerClips.length);

                               for(var rs:int = 0; rs < sections.length; rs++)

                               {

                                trace("sections["+rs+"] is "+sections[rs]);

                               }

                               var w:Number = 0;

                               var l:Number = 0;

                               if(container.numChildren == 0)

                               {

                                trace("container.numChildren is "+container.numChildren);

                            trace('***',sections.length);

                                for(var sx:int = 0; sx < sections.length; sx++)

                                {

                                 trace("sx is "+sx);

                                 var section = sections[sx];

                                 if(sx > 0)

                                 {

                                  section.y = sections[sx-1].y + sections[sx-1].height;

                                  w = section.width;

                                  l = l + section.height;

                                 }

                                 container.addChild(section);

                                }

                               }

                               container.graphics.beginFill(0xfafafa); // Just for background color in container.

                               container.graphics.drawRect(0,0,w,l);

                               container.graphics.endFill();

                               containerClips = sections;

                               for(var p:int = 0; p < containerClips.length; p++)

                               {

                                trace("containerClips["+p+"] is "+containerClips[p]);

                               }

                              

                               return container;

                              } // ----------------------------------------------------------------------------------------- ----------- End public function prepareContainer().

                            • 11. Re: AS3/AIR - for loop being skipped but rest of function runs
                              sawmangs4 Level 1

                              Okay, now we are getting somewhere. With the

                               

                              trace('***',sections.length);

                               

                              placed where you showed the first trace showed a sections.length as *** 4. The second trace showed *** 0.

                              What am I missing? How did sections get emptied when it shows a length of 4 a few lines before it in the same function?

                              • 12. Re: AS3/AIR - for loop being skipped but rest of function runs
                                Colin Holgate MVP & Adobe Community Professional

                                You may have a circular reference. containerClips is the same array as sections. Try this simple test:

                                 

                                var array1 = [1,2,3,4];

                                var array2 = array1;

                                array1.splice(0,array1.length);

                                //array1=[];

                                trace(array2.length);

                                 

                                I feel sure you would expect to see it trace 4, but it trace 0. Now try using the commented out line instead. Now you get a trace of 4.

                                 

                                If somewhere in your code you are making sections also point to the same array as containerClips, when you really meant to duplicate an array, you can use concat instead:

                                 

                                var sections = containerClips.concat();

                                 

                                That would make it be its own duplicate array, and not a pointer to the same array.

                                • 13. Re: AS3/AIR - for loop being skipped but rest of function runs
                                  sawmangs4 Level 1

                                  AWESOME!!!

                                   

                                  I changed to containerClips=[]; and everything works beautifully!

                                   

                                  I do feel stupid but also elated! You all Rock!!!

                                   

                                  Now I have to try and understand what the difference was.

                                   

                                  Thanks so much!

                                  • 14. Re: AS3/AIR - for loop being skipped but rest of function runs
                                    kglad Adobe Community Professional & MVP

                                    the difference is in message 8:  there is a relationship between containerClips and sections