12 Replies Latest reply: Jul 8, 2013 5:49 AM by kglad RSS

    attachMovie & depths

    Ron Colmen Community Member

      I wanbt to be able to create buttons inside dNumHolder_mc everytime loadVars return its value (Each time the number of buttons varie). I used removeMovieClip() to remove the current buttons and tried to recreate the next set of buttons. I believe the issue is due to the depths. But with my code the buttons are created once only. How can recreate buttons eachtime btnsRceLoad receives data?

       

       

      btnsRceLoad.onData = function(src) {

                _root.uusersNow.text = "Total Pages: " + src;

                for(var i:Number=0; i<src; i++){

                          _root.dNumHolder_mc.attachMovie("btnNum","numberBtn"+i,_root.dNumHolder_mc.getN extHighestDepth());

                          _root.dNumHolder_mc["numberBtn"+i]._x = xNumPosition;

                          _root.dNumHolder_mc["numberBtn"+i]._y = yNumPosition;

                          _root.dNumHolder_mc.attachMovie("txtNum","textBtn"+i,_root.dNumHolder_mc.getNex tHighestDepth());

                          _root.dNumHolder_mc["textBtn"+i]._x = xNumPosition;

                          _root.dNumHolder_mc["textBtn"+i]._y = yNumPosition;

                          _root.dNumHolder_mc["textBtn"+i].theNum.text = BtnNumz;

                          xNumPosition = xNumPosition + 24.1;

                          BtnNumz = (BtnNumz + 1);

                }

        • 1. Re: attachMovie & depths
          kglad CommunityMVP

          i don't see where you're removing anything.  but you should use different names and depths:

           

           

           

          btnsRceLoad.onData = function(src) {

                    _root.uusersNow.text = "Total Pages: " + src;

                    for(var i:Number=0; i<src; i++){

                              var mc:MovieClip=_root.dNumHolder_mc.attachMovie("btnNum","numberBtn"+_root.dNumHolder_mc.getNextHighestDepth(),_roo t.dNumHolder_mc.getNextHighestDepth());

                             mc._x = xNumPosition; // assuming this is initialized

                             mc._y = yNumPosition;  // "   "

                              var mc1:MovieClip=_root.dNumHolder_mc.attachMovie("txtNum","textBtn"+_root.dNumHolder_mc.getNextHighestDepth(),_root. dNumHolder_mc.getNextHighestDepth());

                             mc1._x = xNumPosition;

                             mc1._y = yNumPosition;

                             mc1.theNum.text = BtnNumz;  // assuming this is initialized

                              xNumPosition = xNumPosition + 24.1;

                              BtnNumz = (BtnNumz + 1);

                    }

          • 2. Re: attachMovie & depths
            Ron Colmen Community Member

            Thanks Kglad.

             

            I tried your code and it does the same.

             

            Does var mc:MovieClip need to be a new name eachtime btnsRceLoad is called? But how?

            • 3. Re: attachMovie & depths
              kglad CommunityMVP

              yes.

               

              what do you see that makes you think the code is not working?

              • 4. Re: attachMovie & depths
                Ron Colmen Community Member

                I did the below. But no luck.

                 

                var sparkle:Array = [];

                var n:Number = 16;

                for (var j:Number = 0; j < n; j++) {

                var mc:MovieClip = MovieClip(getChildByName("s"+j) );

                sparkle[j] = mc;

                }

                btnsRceLoad.onData = function(src) {

                          _root.uusersNow.text = "Total PagesS: " + src;

                           for(var i:Number=0; i<src; i++){

                                     sparkle[j]=_root.dNumHolder_mc.attachMovie("btnNum","numberBtn"+_root.dNumHolder_mc.getNe xtHighestDepth(),_root.dNumHolder_mc.getNextHighestDepth());

                                     sparkle[j]._x = xNumPosition;

                                    sparkle[j]._y = yNumPosition; 

                                     sparkle[j]=_root.dNumHolder_mc.attachMovie("txtNum","textBtn"+_root.dNumHolder_mc.getNext HighestDepth(),_root.dNumHolder_mc.getNextHighestDepth());

                                     sparkle[j]._x = xNumPosition;

                                     sparkle[j]._y = yNumPosition;

                                     sparkle[j].theNum.text = BtnNumz; 

                                     xNumPosition = xNumPosition + 24.1;

                                     BtnNumz = (BtnNumz + 1);

                • 5. Re: attachMovie & depths
                  kglad CommunityMVP

                  that code makes no sense.  it looks like some as2 and some as3 and none of the as3 would do anything useful.

                   

                  copy and paste the trace output from the following:

                   

                  for(var src:Number=5;src<11;src+=5){

                  testF(src)

                  }

                   

                  function testF(src) {

                            _root.uusersNow.text = "Total Pages: " + src;

                            for(var i:Number=0; i<src; i++){

                                      var mc:MovieClip=_root.dNumHolder_mc.attachMovie("btnNum","numberBtn"+_root.dNumHolder_mc.getNextHighestDepth(),_roo t.dNumHolder_mc.getNextHighestDepth());

                                     mc._x = xNumPosition; // assuming this is initialized

                                     mc._y = yNumPosition;  // "   "

                  trace(src+": "+mc+"_x: "+mc._x+" depth: "+mc.getDepth());

                                      var mc1:MovieClip=_root.dNumHolder_mc.attachMovie("txtNum","textBtn"+_root.dNumHolder_mc.getNextHighestDepth(),_root. dNumHolder_mc.getNextHighestDepth());

                                     mc1._x = xNumPosition;

                                     mc1._y = yNumPosition;

                                     mc1.theNum.text = BtnNumz;  // assuming this is initialized

                                      xNumPosition = xNumPosition + 24.1;

                                      BtnNumz = (BtnNumz + 1);

                            }

                  • 6. Re: attachMovie & depths
                    Ron Colmen Community Member

                    trace:

                    10: _level0.dNumHolder_mc.numberBtn28_x: 337.4 depth: 28

                    • 7. Re: attachMovie & depths
                      kglad CommunityMVP

                      you fail to see 15 lines of trace output???

                      • 8. Re: attachMovie & depths
                        Ron Colmen Community Member

                        Sorry about that Kglad.

                         

                        5: _level0.dNumHolder_mc.numberBtn0_x: 0 depth: 0

                        5: _level0.dNumHolder_mc.numberBtn2_x: 24.1 depth: 2

                        5: _level0.dNumHolder_mc.numberBtn4_x: 48.2 depth: 4

                        5: _level0.dNumHolder_mc.numberBtn6_x: 72.3 depth: 6

                        5: _level0.dNumHolder_mc.numberBtn8_x: 96.4 depth: 8

                        10: _level0.dNumHolder_mc.numberBtn10_x: 120.5 depth: 10

                        10: _level0.dNumHolder_mc.numberBtn12_x: 144.6 depth: 12

                        10: _level0.dNumHolder_mc.numberBtn14_x: 168.7 depth: 14

                        10: _level0.dNumHolder_mc.numberBtn16_x: 192.75 depth: 16

                        10: _level0.dNumHolder_mc.numberBtn18_x: 216.9 depth: 18

                        10: _level0.dNumHolder_mc.numberBtn20_x: 240.95 depth: 20

                        10: _level0.dNumHolder_mc.numberBtn22_x: 265.05 depth: 22

                        10: _level0.dNumHolder_mc.numberBtn24_x: 289.2 depth: 24

                        10: _level0.dNumHolder_mc.numberBtn26_x: 313.3 depth: 26

                        10: _level0.dNumHolder_mc.numberBtn28_x: 337.4 depth: 28

                        • 9. Re: attachMovie & depths
                          kglad CommunityMVP

                          and do you see 15 movieclips attached to _level0.dNumHolder_mc?

                          • 10. Re: attachMovie & depths
                            Ron Colmen Community Member

                            yes.

                            • 11. Re: attachMovie & depths
                              Ron Colmen Community Member

                              Oops!! I know what's wrong...

                               

                              I've forgotten to reset x,y to zero!!!!!

                               

                              Anyway Thanks Kglad!

                              • 12. Re: attachMovie & depths
                                kglad CommunityMVP

                                you're welcome.