Welcome, Guest
  • Author Topic: Adding multiple MC to a MC/scrollpane ?  (Read 2948 times)

    Lundin

    • Server what's that
    • *
    • Posts: 15
      • View Profile
      • Email
    Adding multiple MC to a MC/scrollpane ?
    « on: 08/01/07, 14:21 »
    Hi

    Anyone done that in AS3 ?
    I am only able to put one MC into the scrollpane using the source property. I have tried addChild,source etc with rerfesh..no luck.

    using

    if (i==(cant-1)){
          
       myScrollPane.source =getChildByName("box"+2)
       
       }

    i can add whichever it MC (named box +i here) i want..i just need to add all dynamically added MC into a new MC...and then use this new MC as a scrollpane source.

    Lundin

    • Server what's that
    • *
    • Posts: 15
      • View Profile
      • Email
    Re: Adding multiple MC to a MC/scrollpane ?
    « Reply #1 on: 08/01/07, 14:41 »
    nevermind, solved it..

    var newMCHolder:MovieClip=new MovieClip

    in the getTitles_result function (see Jorge's tutorial on amfphp remoting)

    if (i==(cant-1))

    in a for loop adding all created MC (which is dervied for base)

    newMCHolder.addChild(getChildByName("box"+j))

    then
    myScrollPane.source =newMCHolder      

    Lundin

    • Server what's that
    • *
    • Posts: 15
      • View Profile
      • Email
    Re: Adding multiple MC to a MC/scrollpane ?
    « Reply #2 on: 08/05/07, 20:47 »
    Need some help here...the code above add a MC to the Scrollpane (which is a MC with a scroll)..anyway i wish to dynamically add new MC's (the base) to this scrollpane upon pressing a button  without remove the previous ones.

    I dont get the update or invalidate methods becuase what the code below does, it that it indeed add the new MC and expand the scollpane, but at the same time remove the previous added MC's. i did this code in As2 and it worked great when using getNextDepth but i am quite sure that with addChild there is no such thing...anyway .i tried doing like this

    adder.addEventListener("mouseDown", changeIt);

    var ypos:int;

    function changeIt(cb:Object)  {

    for (var i=0;i<3;id++) {

      var abox:MovieClip = new MovieClip();
      var it:base = new base();
      abox.name = "box"+i;
      ypos +=20
      abox.y = (ypos*i);

     
      addChild(abox);
      abox.addChild(it);
     
       
    if (i==2){
      var aNewBox:MovieClip = new MovieClip();
       
       for (var ik=0;ik<2;ik++) {
            aNewBox.addChild(getChildByName("box"+ik))
            myScrollPane.source= aNewBox
            myScrollPane.update()

        }
      }
    }
     

    any ideas...just seeing the code..i do understand why it happends becuse a New Box..just change the Coordinates and then send it to scrollpane :-[
    Will addChildAt help me something ?
    « Last Edit: 08/05/07, 21:10 by Lundin »

    Jorge Solis

    • Global Moderator
    • Systems Administrator
    • *****
    • Posts: 14616
      • View Profile
    Re: Adding multiple MC to a MC/scrollpane ?
    « Reply #3 on: 08/06/07, 01:30 »
    Replacing the source of a scrollpane removes previous content, that's the way the components work. A better approach to manage your content will be use a custom pane, I mean build your own using an MC, a mask and a scrollbar component.

    Jorge

    Lundin

    • Server what's that
    • *
    • Posts: 15
      • View Profile
      • Email
    Re: Adding multiple MC to a MC/scrollpane ?
    « Reply #4 on: 08/06/07, 10:52 »
    Jorge, that is a good solution. One can use onebyonedesign (OBO FullScrollBar class for that...i just did..goole that one if you need it) for instance.

    BUT, i have to say after several hours trying to undertsand why updating my scrollpane source didn't do what i expected i finally found a way around it. Basically what i did wrong was that i  created a MC inside the for loop.
    As you said the next coming MC will remove the former, so you need a MC which is updated (or actually more like repainted with the new base MC) and then insted of making a scrollbar around this, updating the scrollPane. In my case this is enough, but i am not sure how good it's if previous values changes for instance..

    in the base MC i have black rectangle which upon pressing the adder button adds 1 of these into the scrollpane.


    adder.addEventListener("mouseDown", changeIt);
     
     
    var aBox:MovieClip = new MovieClip();
    var xPos:int;

    function changeIt(cb:Object)  {
    //attaching blueMovie to the content location stored in mcMain
     i=i++
     triggers=triggers+3 // some values i just need to reposition the MC
     
       var itz:base=new base
       addChild(itz);
       itz.name="boxy"+triggers;
       itz.x=2;
       itz.y=(10*triggers)+10;
          
       
           
    addChild(aBox);
    aBox.addChild(getChildByName("boxy"+triggers))
          
    myScrollPane.source=aBox
     }