Combining dynamic text boxes based on their width

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
		Text.last_name.x = Text.first_name.x + Text.first_name.textWidth + 10;

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.

Dear didikunz,

When I add this line of code to one template:

text1.f0.autoSize = TextFieldAutoSize.LEFT;

when I test inside Animate, it works great. But when I try to generate the template with template generator, I get the following Error:

1120: Access of Undefined Property TextFieldAutoSize.

Any suggestions?

Thanks in Advance.

If I understood correctly you wish to have different styles in the same text box.
With Actionscript you can put HTML formatted text and so change styles in the middle of the text with tags.
Unfortunately I cannot find the working prototype, so I made a little search and should be something like this

var myText:String = "<p>This is <b>some</b> content to <i>render</i> as <u>HTML</u> text.</p>"; 
myTextBox.htmlText = myText;

well I do remember the .htmlText but not much more
I hope it helps

Adobe Help Text Reference

Is text1.f0 a movieClip with a textfied inside? text1 would be the movieClip and f0the TextField, right? If yes, I don’t understand, why it should not work.

Hi Didikunz,

Thanks a lot for your prompt reply and the help, I finally figured it out, I forgot to import flash.textFieldAutoSize.

Now it’s working fine, but something is messing with the mask that I’ve added, when timeline reaches the first stop() action, when trying to play out animation, it just jumps to the last frame instead of playing all the frames. I’ll upload also the .fla file tomorrow .