Skip to main content
Participating Frequently
August 25, 2009
Answered

Unit testing with TLF

  • August 25, 2009
  • 1 reply
  • 2147 views

While unit testing complex formating, I hit several problems. Below are simple tests that fail with an error. Does anybody know what is wrong with these tests?

Thanks for any hints,

Marc

    public function test_apply_Link():void 
    {
        var init:XML = <TextFlow xmlns="http://ns.adobe.com/textLayout/2008"><p><span>aaa</span></p></TextFlow>
        var textFlow:TextFlow = TextConverter.importToFlow(init, TextConverter.TEXT_LAYOUT_FORMAT)
        var editManager:IEditManager = new EditManager()
        textFlow.interactionManager = editManager
       
        editManager.selectRange(1,2)
        editManager.applyLink("http://livedocs.adobe.com/", "_self", true) // throws error:
        /*    
        RangeError: Error #2006: The supplied index is out of bounds.
            at flash.text.engine::GroupElement/replaceElements()
            at flashx.textLayout.elements::ParagraphElement/http://ns.adobe.com/textLayout/internal/2008::insertBlockElement()
            at flashx.textLayout.elements::FlowLeafElement/http://ns.adobe.com/textLayout/internal/2008::createContentElement()
            at flashx.textLayout.elements::SpanElement/http://ns.adobe.com/textLayout/internal/2008::createContentElement()
            at flashx.textLayout.elements::ParagraphElement/http://ns.adobe.com/textLayout/internal/2008::createTextBlock()
            at flashx.textLayout.elements::ParagraphElement/http://ns.adobe.com/textLayout/internal/2008::createContentElement()
            at flashx.textLayout.elements::SubParagraphGroupElement/http://ns.adobe.com/textLayout/internal/2008::setParentAndRelativeStart()
            at flashx.textLayout.elements::LinkElement/http://ns.adobe.com/textLayout/internal/2008::setParentAndRelativeStart()
            at flashx.textLayout.elements::FlowGroupElement/replaceChildren()
            at Function/http://adobe.com/AS3/2006/builtin::apply()
            at flashx.textLayout.elements::ParagraphElement/replaceChildren()
            at flashx.textLayout.edit::TextFlowEdit$/insertNewSPBlock()
            at flashx.textLayout.edit::TextFlowEdit$/makeLink()
            at flashx.textLayout.operations::ApplyLinkOperation/doOperation()
            at flashx.textLayout.edit::EditManager/doInternal()
            at flashx.textLayout.edit::EditManager/doOperation()
            at flashx.textLayout.edit::EditManager/applyLink()
             */
    }

    public function test_undo():void 
    {
        var init:XML = <TextFlow xmlns="http://ns.adobe.com/textLayout/2008"><p><span>aaa</span></p></TextFlow>
        var textFlow:TextFlow = TextConverter.importToFlow(init, TextConverter.TEXT_LAYOUT_FORMAT)
        var undoManager:IUndoManager = new UndoManager()
        var editManager:IEditManager = new EditManager(undoManager)
        textFlow.interactionManager = editManager
       
        editManager.selectRange(1,2)
         var format:TextLayoutFormat = new TextLayoutFormat()
        format.fontWeight = FontWeight.BOLD
        editManager.applyLeafFormat(format)
       
        undoManager.undo() // throws error:
        /*    
        TypeError: Error #1009: Cannot access a property or method of a null object reference
            at flashx.textLayout.edit::EditManager/performUndo()
            at flashx.textLayout.operations::FlowOperation/performUndo()
            at flashx.undo::UndoManager/undo()            
        */
    }
This topic has been closed for replies.
Correct answer wluo

For your first problem, you missed displaying the textFlow to the stage.  The code below works:

var

var controllerOne:ContainerController = new ContainerController(container, 500, 500);

var init:XML = <TextFlow xmlns="http://ns.adobe.com/textLayout/2008"><p><span>aaa</span></p></TextFlow>

var textFlow:TextFlow = TextConverter.importToFlow(init, TextConverter.TEXT_LAYOUT_FORMAT)

addChild(container);

textFlow.flowComposer.addController(controllerOne);

textFlow.flowComposer.updateAllControllers();

var editManager:IEditManager = new EditManager();

textFlow.interactionManager = editManager;

editManager.selectRange(1,2);

editManager.applyLink(

"http://livedocs.adobe.com/", "_self", true);

container:Sprite = new Sprite();

1 reply

wluoCorrect answer
Participating Frequently
September 10, 2009

For your first problem, you missed displaying the textFlow to the stage.  The code below works:

var

var controllerOne:ContainerController = new ContainerController(container, 500, 500);

var init:XML = <TextFlow xmlns="http://ns.adobe.com/textLayout/2008"><p><span>aaa</span></p></TextFlow>

var textFlow:TextFlow = TextConverter.importToFlow(init, TextConverter.TEXT_LAYOUT_FORMAT)

addChild(container);

textFlow.flowComposer.addController(controllerOne);

textFlow.flowComposer.updateAllControllers();

var editManager:IEditManager = new EditManager();

textFlow.interactionManager = editManager;

editManager.selectRange(1,2);

editManager.applyLink(

"http://livedocs.adobe.com/", "_self", true);

container:Sprite = new Sprite();

Participating Frequently
September 10, 2009

For your second issue, you didn't display TextFlow before you selected the Text.  I also changed the FontWeight.BOLD to "bold" in order to pass compilation.  The code below should work:

var

var controllerOne:ContainerController = new

ContainerController(container, 500, 500);

var undoManager:IUndoManager = new UndoManager()

var init:XML = <TextFlow xmlns="http://ns.adobe.com/textLayout/2008"><p><span>aaa</span></p></TextFlow>

var textFlow:TextFlow = TextConverter.importToFlow(init, TextConverter.TEXT_LAYOUT_FORMAT)

addChild(container);

textFlow.flowComposer.addController(controllerOne);

textFlow.flowComposer.updateAllControllers();

var editManager:IEditManager = new EditManager();

textFlow.interactionManager = editManager;

editManager.selectRange(1,2)

var format:TextLayoutFormat = new TextLayoutFormat();

format.fontWeight =

"bold";

container:Sprite = new Sprite();

editManager.applyLeafFormat(format);

undoManager.undo();

textFlow.flowComposer.updateAllControllers();

Participating Frequently
September 11, 2009

indead, that works.

Thanks,

Marc