Skip to main content
Inspiring
July 5, 2013
Question

attachMovie & depths

  • July 5, 2013
  • 1 reply
  • 1671 views

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.getNextHighestDepth());

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

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

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

                    _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);

          }

This topic has been closed for replies.

1 reply

kglad
Community Expert
Community Expert
July 5, 2013

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);

          }

Inspiring
July 5, 2013

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?

kglad
Community Expert
Community Expert
July 5, 2013

yes.

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