Skip to main content
Participating Frequently
May 28, 2009
Question

Setting dynamic widths for textfields in as3?

  • May 28, 2009
  • 2 replies
  • 710 views

I have 3 textfields. they're in a sprite container. 1. date 2. pipe_mc movieclip 3. title field. I need to set it so that the textfield/mc/textfield;s x property changes dynamically when a shorter or longer date gets added into the field, via XML.

Here is the code:

addChild(dateline);

dateline.addChild(date_txt);
dateline.addChild(title_txt);
dateline.addChild(pipe_mc);
date_txt.x = 3;

var spacer:Number = 10;

if (date_txt.textWidth >= 90) {

pipe_mc.x = date_txt.x + date_txt.width + 18;
title_txt.x = pipe_mc.x + pipe_mc.width + spacer;

                        }

else if (date_txt.textWidth <= 90) {

pipe_mc.x = date_txt.x + date_txt.width - 18;
title_txt.x = pipe_mc.x + pipe_mc.width + spacer;
pipe_mc.visible = true;

                        }

Any help or suggestions are welcome
Thanks

This topic has been closed for replies.

2 replies

kglad
Community Expert
Community Expert
May 28, 2009

there's a textfield in pipe_mc whose x property you want to assign?

Participating Frequently
May 28, 2009

i want to assign the fields so that the space between closes up when a shorter date is on th field in the date field
pipe_mc is a movieclip between

Participating Frequently
May 28, 2009

so the x properties of pipe_mc and title_txt need to move

Ned Murphy
Legend
May 28, 2009

Do you have the textfield set up to be autoSized?  Is there a reason for having three textfields separate rather than combining the text into one textfield with sufficient spacing between the entries?

Participating Frequently
May 28, 2009

I have the xml set up for different nodes and and i don't think i can change it now