Skip to main content
Participant
August 3, 2010
Question

Formatting a Flash TLF which is on the stage

  • August 3, 2010
  • 1 reply
  • 5073 views

I am using Flash CS5.

I have the simplest possible FLA. It has a TLF on the stage.

The TLF has a font size of 32 and contains a few characters. Its instance name is "txt".

The following AS3 code:

trace(txt.defaultTextFormat.size);
trace(txt.direction);

Produces:

12
null

Which is plain wrong. When I try to change the direction with:

txt.direction = "rtl";

nothing happens.

However, when I create a new TLFTextfield using code alone everything works well.

I need to be able to edit stage-based TLFs as well as I do with dynamic ones. How can I do it?

This topic has been closed for replies.

1 reply

Participating Frequently
August 3, 2010

Howdy Gil,

I have the answers to your questions.

The first is why defaultTextFormat is not 32 and is instead 12. This is by design, the defaultTextFormat for TLF is not based on what is set in the Authoring environment. Instead, if you have not set it, it uses the defaults that TextField uses which is 12 point Times New Roman.

The second is direction outputting a null. This is a bug. If it is never set in the authoring environment, the container does not have that attribute set, so it is returning null, which is wrong. If you toggle the direction and then run it, you will get the correct value.

The third is the ability to change Authoring created text blocks direction through AS. What is going on is in the Authoring environment, the TLF Markup that is created contains the direction property on a paragraph by paragraph basis and this value overrides the direction that is set on the container, similar to CSS styles. We discovered this as well as we were working on adding style sheet capabilities to TLF. Currently the only way to fix this is to walk every node of the TLF mark up and change the direction to the correct option. I have included the code for a function that will do just that.

import flashx.textLayout.formats.TextLayoutFormat;
import flashx.textLayout.elements.TextFlow;
import flashx.textLayout.edit.EditManager;
import flashx.textLayout.edit.SelectionState;
import flashx.textLayout.edit.ISelectionManager;

setDirection(txt.textFlow, "rtl");

function setDirection(tf:TextFlow, strDirection:String):void
{
    var fmt:TextLayoutFormat = new TextLayoutFormat();
    fmt.direction = strDirection;
   
    // Get the current interaction manager state so it can be reset
    var tmpInt:ISelectionManager = tf.interactionManager;

    var editManager:EditManager = new EditManager();
    tf.interactionManager = editManager;
   
    // Wrap up the format change in a composite operation.
    editManager.beginCompositeOperation();
   
    var setTextFormatSelectionState:SelectionState;

    // Select all the text and apply the new paragraph format.

    setTextFormatSelectionState = new SelectionState(tf, tf.getAbsoluteStart(), tf.flowComposer.getControllerAt(0).textLength-1);
    editManager.applyParagraphFormat(fmt, setTextFormatSelectionState);                   
    editManager.endCompositeOperation();

    // Restore the original interaction manager.
    tf.interactionManager = tmpInt;

}

Hope this helps,

Craig Simmons

Flash Authoring

Participant
August 4, 2010

Hello Craig

Thanks for the speedy reply.

This might sound picky, but that choice to create a null defaultTextFormat pulls the carpet below the authoring process. The idea in an authoring environment is that the graphical data will be stored onscreen instead of being coded. This may be necessary when one wishes to take an existing TLF enlarge or reduce its font size, change its weight etc. Of course one can argue that the same can be pre-coded. But if so, then what is the stage good for?

Another bug I have encountered is the inability to sete antiAliasing to a TLF if it is empty while setting its format. So, for example, if txt.text == "" then it will never be AAed. There are simple tricks around it (such as adding an empty space).

This code for example will work only if txt is not empty:

var font:Font = new Font1();

var format:TextFormat = new TextFormat(font.fontName, 36, 0);

txt.setTextFormat(format);

txt.embedFonts = true;
txt.antiAliasType = AntiAliasType.ADVANCED;
txt.text = "abc";

Also it would be wonderful if:

1) There would be a bundle of easy-to-understand tutorials to learn about TLF. The documentation is scattered all over the web and unless I am missing something, it is on the verge of non-existent.

2) The Adobe team would create a reasonable abstraction layer for the TLF. The code you supplied, as wonderful as it is, is ridiculously complicated to adjust just a single property!

Sorry for the rants. It is truly great that the Adobe team has finally come up with a BIDI solution. Just please make it a little more friendly.

Thanks again

Gil

Participating Frequently
August 6, 2011

So, how do you get the size that was set in the authoring environment?