5 Replies Latest reply on Mar 25, 2011 6:00 PM by kglad

    Scrollpane with dynamically added movieclips

    John Hall Level 4

      I'm more of a Flex than Flash developer so I'm hopeful this is something easy.  Short story, I have a scrollpane in a flash-created swf. In my pure AS3 project I dynamically create menuitems within a new movieclip.

       

       

      for ( var j : uint = 0; j < items.length; j++ ) {

           var menuItemRenderer : MenuItemRenderer = new MenuItemRenderer( items[ j ]);

           menuHolder.addChild( menuItemRenderer );

           menuItemRenderer.y = RENDERER_HEIGHT * counter;  // renderer hight is 56

       

           ++counter;

      }

      scrollpane.source = menuHolder;

       

       

      Two problems:

       

      1. Even if I add an event listener for Event.COMPLETE on the scrollpane component, it never fires. Is there another even that can be used to fire off something when the movieClip is done loading inside the pane?
      2. Despite the movieClips (itemRenderers in my terms) displaying properly on the screen, if I trace the height and width of the movieClip, they're both 0.

       

      I've tried all of these:

       

       

      scrollpane.invalidate("all", true);

      scrollpane.invalidate();

      scrollpane.update();

      scrollpane.refreshPane();

       

       

      at various times and nothing appears to work. Any suggestions on where to go next?

       

      Alternatively, does anyone have a custom scrollbar/pane for dynamically generated content that they think might be a better match for something like this?

       

      Thanks much.

        • 1. Re: Scrollpane with dynamically added movieclips
          kglad Adobe Community Professional & MVP

          is something being loaded in MenuItemRenderer?

          • 2. Re: Scrollpane with dynamically added movieclips
            John Hall Level 4

            Thanks for taking the time to look at this. I'm a bit baffled.

             

            Yes, a thumbnail and some text description are dynamically being loaded into the itemRenderer. That seems to work fine as when I have 10 menu items they load the appropriate thumbnail based on a source url (haven't done the text yet but should be fine) and those are loaded into the menuHolder movieClip which starts out as a new MovieClip. When I do then go and make menuHolder (the movieClip with the itemRenderers) the source of the scrollPane, they appear in what seems to be the correct location the navigation panel (this is a slide up tray that has this scrollpane inside another movieclip) so visually everything looks right. However, the scrollbar is never enabled and if I trace the code it things the scrollpane.source movieClip height and width are 0, which might explain why the scrollbar never enables because it doesn't think the movieclip content is outside the mask area. At least that's my intuitive take on it.

             

            PS, if I load an external SWF into the scrollPane using the exact same method, it works properly, so it has something to do with dynamically creating movieClips within the new source movieClip. If I try to set the height or width of that moveClip (menuHolder) before adding it to the pane, nothing renders. So, in summary, if I simply add the itemRenderers to a blank movieClip they render OK in what appears to be the scrollPane but width and height trace as 0 despite obviously taking up something like 600 x 800 when all the itemRenderers are done being inserted.

             

            Message was edited by: John Hall to add PS

            • 3. Re: Scrollpane with dynamically added movieclips
              kglad Adobe Community Professional & MVP

              after loading is complete (use a listener or listeners), you'll need to invalidate() the scrollpane so it can be redrawn with the loaded content.

              • 4. Re: Scrollpane with dynamically added movieclips
                John Hall Level 4

                That was part of the original problem. Since I'm doing all of this in AS3, including creating the new instance of the scrollpane, I tried to addEventListener(Event.COMPLETE) to scrollpane but it never fires.  I've also, for diagnostic grins, started a timer after the load for a second later then fire scrollpane.refreshPane() and scrollpane.update(), neither of which does anything.

                 

                So maybe there's a principle that I'm missing. What is the significant difference between a movieClip created with AS3 and an externally loaded SWF that might account for that, if you have any ideas?

                • 5. Re: Scrollpane with dynamically added movieclips
                  kglad Adobe Community Professional & MVP

                  there are so many differences i don't even know where to start.  but, more importantly, i don't think it's related to the problem.

                   

                  you need to dispatch an event from the class that's loading external swfs to the class that contains your scrollpane.  that doesn't have to be direct.

                   

                  you may dispatch from one class, listen in another, dispatch from that other and eventually notify your scrollpane it should invalidate().

                  1 person found this helpful