dynamic text field part I – letter spacing

Just discovered that flash resets the author-time letter spacing of a dynamic textfield when the textfield’s text is set in ActionScript.

To maintain the authortime letter spacing settings of the textfield, you need to record the textfield’s textformat, set the text, and then reset the textfield’s textformat to what it was. For example, if your textfield’s instance name is test:

var fmt:TextFormat = test.getTextFormat();
test.text=”New text”;
test.setTextFormat(fmt);

something to check is that if the textfield does not contain any text, the author-time TextFormat
letter spacing property is not recorded. So if you don’t want your textfield to contain any text, make sure the textfield contains at least one space to ensure it maintains its author-time TextFormat letter spacing property.

Interactive developer, Author - iOS development with Swift - book coming 2017 https://manning.com/books/ios-development-with-swift

Tagged with: , ,
Posted in Flash
9 comments on “dynamic text field part I – letter spacing
  1. I cant get this (letter spacing) to work with a dynamic text field from an XML file –

  2. here is my code:// item properties assigned from XML var fmt:TextFormat = cur_item.menu_txt.getTextFormat(); curr_node = node_xml.childNodes[i]; curr_item.action = curr_node.attributes.action; curr_item.variables = curr_node.attributes.variables; curr_item.menu_txt.setTextFormat(fmt); curr_item.menu_txt.text = curr_node.attributes.name;

  3. yeah i don’t think it’s related to the source of the text. You need to set the TextFormat of your textfield AFTER setting the text of the textfield.So swap the last two lines of your code and it should work.

  4. Trys says:

    well spotted – you’ve just saved me an hour of annoyance. have you logged a bug with Adobe for this?

  5. yeah thanks that hour of annoyance was pretty annoying too! it hadn’t occurred to me to log the letter spacing bug, but i have now, cheers.

  6. 123 says:

    is there a solution for htmlText with links?

    This solutions works great if you don't use html

  7. Yeah 123, i can see your problem.

    Using setTextFormat to set the textFormat of a textfield will replace any textformatting you applied to the textfield previously. this includes any textformatting created via htmltext, such as bold, italic or even anchor tags.

    However, you can apply the textFormat object as a default to the textField, before setting the htmlText. You can do this like so:

    var fmt:TextFormat = test.getTextFormat();
    test.defaultTextFormat=fmt;
    test.htmlText=”Click here for more information.”;

    This way, the formatting applied by the htmlText property doesn't get overridden.

  8. 123 says:

    hi craig,

    you're right, if you would do this in as3!!!

    the declaration defaultTextFormat doesn't exists in as2.

    the only solution – if you would call it as a solution – i found is to set the test.url = '' to the hole textfield!

    So, is there a real usable solution for html in as2?

  9. ah. the plot thickens. I think you're right, to retain the styling in AS2 you have to set the TextFormat of a textfield after setting the text or htmlText property, which doesn't work with styling in htmlText.

    I think what you might want to have a look at is the StyleSheet class and the TextField.styleSheet property. The StyleSheet class has a letterSpacing property that you could use to retain the textField's letter-spacing.

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: