Combining dynamic text boxes based on their width


#1

Hey everyone.

I need to be able to combine two or more dynamic text boxes in my flash template, based on information sent from the cgData when playing the template.

Information is sent in (i.e. first name in regular font & last name in bold font), and I would like based on the width of each text box to display the first name aligned left, and the last name immediately next to it, so as to appear as the full name.

I have managed to make the text boxes expandable so as to grow or shrink to the contents (by double clicking on the bottom right of the text boxes so as to unlock the fixed width handle).

I then inside an .as file assign the x position of the last_name to first_name.x + first_name.textWidth and works fine using dummy text inside the .fla.

When I try to call this template inserting it with cgData however, the calculations are wrong since it is still calculating based on the dummy text in the .fla, and not the width of the data that is sent in.

I know this is more of an actionscript question, but is there somewhere i.e. a function or something that I can override in Caspar, where I can call my resize methods after the data is sent in and the values are the ones sent in?

I have tried overriding the SetData method, but still no use:

public class Main extends CasparTemplate
{
	override public function SetData(xmlData:XML):void
	{
		super.SetData(xmlData);
		
		Text.last_name.x = Text.first_name.x + Text.first_name.textWidth + 10;
	}
}

#2

I don’t think that works.

Also override postInitialize and set the autoSize property:

Text.last_name.autoSize = TextFieldAutoSize.LEFT;

That makes the field adapt it’s width to the text. Be sure to NOT set the line to wrap. Then use width instead of textWidth:

Text.last_name.x = Text.first_name.x + Text.first_name.width + 10;

That should do it.