5 Replies Latest reply on Sep 12, 2011 8:53 AM by Ned Murphy

    centerTF

    Ron Colmen Level 2

      I'm creating a TextField. How do I center it to a perticular movieclip (ab_mc).

       

      createTF(_root.ab_mc._x+_root.ab_mc._width/2,_root.ab_mc._y+_root.ab_mc._height/2,""); //this doesn't work though!

       

      Message was edited by: Ron Colmen

        • 1. Re: centerTF
          Ned Murphy Adobe Community Professional & MVP

          You determine the width of the mc and the width of the textfield and use the _x property of the mc to determine where to place the _x property of the textfield.  The _x property of the textfield should be...

           

          tf._x = mc._x + ((mc._width - tf._width)/2);

           

          (assuming the mc registration is to its left side)

          • 2. Re: centerTF
            Ron Colmen Level 2

            not sure why? didn't work.

             

            newTF.onRelease=function(){

            createTF(_root.ab_mc._x + ((root.ab_mc._width - root.ab_mc.new_mc.tf._width)/2));

            }//this piece of code is in another movieclip

             

            Also how do I add the ._y property here?

             

            Message was edited by: Ron Colmen

            • 3. Re: centerTF
              Ned Murphy Adobe Community Professional & MVP

              I have no idea what your createTF function does, so I cannot tell why it won't.

              • 4. Re: centerTF
                Ron Colmen Level 2

                var tl:MovieClip = this;

                 

                function createTF(x:Number,y:Number,s:String):Void{

                var tf_mc:MovieClip = tl.attachMovie("tfID1.tf_mc_"+textNum++,tl.getNextHighestDepth());

                • 5. Re: centerTF
                  Ned Murphy Adobe Community Professional & MVP

                  Your function doesn't appear to make use of any of the parameters you are passing to it, nor even to create a textfield.  It seems like you can't get something working because you haven't done anything to get it working.  Try looking up the createTextField method in the Flash help documentation if you want to see how to create a textfield dynamically and how to place it where you want it to be.