dcsimg
A Flash Developer Resource Site

Results 1 to 2 of 2

Thread: How to put a dynamic text field in center stage

  1. #1
    Member
    Join Date
    Oct 2006
    Posts
    48

    How to put a dynamic text field in center stage

    Hello

    I've managed to put a text field onto the stage using AS2 but now I'm trying to make it stay in the center of the stage. Here's the code I used;

    code:
    this.createTextField("dynamic_txt",1,(Stage.width/2),(Stage.height/2),1,1);
    dynamic_txt.text = "This is just a test to see if this works.";
    var textstyle:TextFormat = new TextFormat();
    textstyle.size = 18;
    textstyle.font = "Arial";
    dynamic_txt.setTextFormat(textstyle);
    dynamic_txt.autoSize = true;



    Right now it looks like this;


    How do I make it look like this?


    Thanks

  2. #2
    the naked eye waynenort's Avatar
    Join Date
    Jan 2002
    Location
    Melbourne, Australia
    Posts
    334
    Hey Humbuged - It has centered it, but the starting point of your dynamic text is cented to the stage. You need to get the width of the text box(297pixels), halve it and minus it from your original centering calculation.
    code:
    this.createTextField("dynamic_txt",1,(Stage.width/2),(Stage.height/2),1,1);
    dynamic_txt.text = "This is just a test to see if this works.";
    var textstyle:TextFormat = new TextFormat();
    textstyle.size = 18;
    textstyle.font = "Arial";
    dynamic_txt.setTextFormat(textstyle);
    dynamic_txt.autoSize = true;
    trace (dynamic_txt._width)
    dynamic_txt._x -= dynamic_txt._width/2


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center