4 Replies Latest reply on Apr 8, 2011 12:01 PM by Rothrock

    A scroll bar/scrollPane

    Ron Colmen Level 2

      I'm having some buttons populated in to a mc (using a mysql db). At the moment there are abut 700 buttons. But I don't know how to get it into a scrollPane or some other way so has a scroll bar beside this mc.

        • 1. Re: A scroll bar/scrollPane
          Ron Colmen Level 2

          I'm still stucked in this... The scroll pane won't scroll or show the dynamic content. I did some research and I found that this could be fixed by adding .refresh(); But that did not solve the case. Could someone show me how to get the dynamic content in to the scrollpane? Thanks.

           

          //content path (Componant inspector): patHolder

           

          var senderLoad:LoadVars = new LoadVars();

          var receiveLoad:LoadVars = new LoadVars();

          senderLoad.sendAndLoad("http://www.web.com/the.php",receiveLoad,"POST");

          receiveLoad.onData = function(src) {

               var messageA:Array = src.split(",,,");

               messageA.pop();


          var xPosition:Number = 0;

          var yPosition:Number = 0;

           

          for(var i:Number=0; i<messageA.length; i++){

                     var msgA:Array = messageA[i].split(",,");

           

          _root.patHolder.attachMovie("XBtn1","btn"+i,_root.patHolder.getNextHighestDepth());


          _root.patHolder["btn"+i]._x = xPosition;

          _root.patHolder["btn"+i]._y = yPosition;

           

          yPosition = yPosition + 31.0;


          _root.patHolder["btn"+i].textBlack.text = msgA[0];

          }

          scrollerGS.refresh();

          }

          • 2. Re: A scroll bar/scrollPane
            Rothrock Level 5

            I'm guessing that patHolder is some clip in your library that is being exported for actionscript?

             

            In that case then you will want to get the actual content instance.

             

            var myContent:MovieClip= scrollerGS.content

             

            And then you would attach the buttons using:

             

            var currentButton:MovieClip=myContent.attachMovie("XBtn1","btn"+i,1000+i);

             

            curButton._x=xPosition;

            curButton._y=yPosition;

             

             

            Also when you are done I don't think you want to use refresh(). I think that will just reload the patHolder—without the attached buttons! Instead I think you should use the invalidate() method.

            • 3. Re: A scroll bar/scrollPane
              Ron Colmen Level 2

              I initially had the patHolder on the swf stage (not exported to actionscript) and then after the buttons are populated i tried to use the refresh() to make the scroll pane work. After reading your post I tried the following, but I'm a bit lost here.

               

               

              //content path (Componant inspector): patHolder

               

              var myContent:MovieClip= scrollerGS.content

               

              var senderLoad:LoadVars = new LoadVars();

              var receiveLoad:LoadVars = new LoadVars();

              senderLoad.sendAndLoad("http://www.web.com/the.php",receiveLoad,"POST");

              receiveLoad.onData = function(src) {

                   var messageA:Array = src.split(",,,");

                   messageA.pop();


              var xPosition:Number = 0;

              var yPosition:Number = 0;

               

              for(var i:Number=0; i<messageA.length; i++){

                         var msgA:Array = messageA[i].split(",,");

               

              //_root.patHolder.attachMovie("XBtn1","btn"+i,_root.patHolder.getNextHig hestDepth());

               

              var currentButton:MovieClip=myContent.attachMovie("XBtn1","btn"+i,1000+i) ;

               

              //_root.patHolder["btn"+i]._x = xPosition;

              //_root.patHolder["btn"+i]._y = yPosition;

               

              currentButton._x=xPosition;

              currentButton._y=yPosition;

               

              yPosition = yPosition + 31.0;


              _root.patHolder["btn"+i].textBlack.text = msgA[0];

              }

              scrollerGS.invalidate();

              }

              • 4. Re: A scroll bar/scrollPane
                Rothrock Level 5

                I generally recommend that when you are trying something new to set aside the actual project you are working on and try it in a separate little test file. That way you can figure it out in a simpler format and move it toward more complexity and at each step more clearly see what might be stuffing it up if you encounter problems.

                 

                So make a new file.

                 

                In the library create some kind of simple clip for your "holder" and set it to export for actionscript. Also make a simple little square button or something and set it to export for actionscript. Then add a scrollpane to the stage. First make sure that you can get the holder into the scrollpane

                 

                import mx.containers.ScrollPane;

                 

                var sp:ScrollPane;

                 

                sp.contentPath="MyHolderFromLibrary"; //That should be the linkage id you gave it in the export dialog

                 

                Do you see the holder from the library? Okay. Next step. See if you can get a reference to that.

                 

                var myContent:MovieClip=sp.content;

                trace("My content is located at: "+myContent);

                 

                Does that give you something other than undefined? If so you are ready to attach a button (or three!)

                 

                for(var i=0;i<3;i+

                var curButton:MovieClip=myContent.attachMovieClip("MyButton","myButton"+i,1000+i);

                trace("Attached: "+curButton);

                curButton._x=i*50;

                curButton._y=i*50;

                }

                 

                Did that work? I'm guessing you will get traces, but won't see the buttons. If so then add the final bit.

                 

                sp.invalidate();

                 

                That should do it. Once you get it working there bring it into your existing project. If it stops working then you might have an incorrect path or perhaps some kind of timing issue with the externally loaded assets. But overall it will be easier to solve.