Skip to main content
Known Participant
November 10, 2010
Question

Textflow link element doesn't work after append to an existed textflow

  • November 10, 2010
  • 2 replies
  • 6468 views

It's a strange problem

I have two textflow container : RichEditableText

the first one I new the textflow2 everytime I clicked the button,and append a link returned by getElement

the second one I initially new a textflow and reused it to append new link returned by the same function getElement

but the strange thing is , the first one works just fine ,but the second one 's link seems invalid with no hand cursor nor function

thanks a lot for any clue or comment

<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
                           xmlns:s="library://ns.adobe.com/flex/spark"  
                           xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="400" minHeight="300">
        <s:layout>
                <s:BasicLayout/>
        </s:layout>
        <fx:Script>
                <![CDATA[
                        import flashx.textLayout.elements.LinkElement;
                        import flashx.textLayout.elements.ParagraphElement;
                        import flashx.textLayout.elements.SpanElement;
                        import flashx.textLayout.elements.TextFlow;

                        [Bindable] public var textFlow:TextFlow = new TextFlow();
                       
                        [Bindable] public var textFlow2:TextFlow = new TextFlow();
               
                               
                        protected function button1_clickHandler(event:MouseEvent):void
                        {
                                textFlow2 = new TextFlow();
                                textFlow2.addChild(getElement());
                               
                               
                                textFlow.addChild(getElement());
                         }
                       
                       
                       
                        private function getElement():ParagraphElement{
                                var linkSpan:SpanElement = new SpanElement();
                                linkSpan.text = "link";
                                var link:LinkElement = new LinkElement();
                                link.addChild(linkSpan);
                                link.href = "event:ok"
                                var p:ParagraphElement = new ParagraphElement();
                                p.addChild(link);
                                return p;
                        }

        
                ]]>
        </fx:Script>
        <fx:Declarations>
                <!-- -->
        </fx:Declarations>
        <s:RichEditableText editable="false" text="RichText" width="180" height="165"  textFlow="{textFlow2}" />
        <s:RichEditableText editable="false" x="196"   text="RichText" width="180" height="165" textFlow="{textFlow}" />
        <s:Button x="116" y="217" label="button" click="button1_clickHandler(event)"/>
</s:Application>

This topic has been closed for replies.

2 replies

Known Participant
June 29, 2011

I'm facing the same issue and i'm using 4.5 SDk.

Here's my code. Works fine if textFlow value is not bindable, else shows nothing(Blank).

<?xml version="1.0" encoding="utf-8"?>

<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"

   xmlns:mx="library://ns.adobe.com/flex/mx"

   xmlns:s="library://ns.adobe.com/flex/spark"

   creationComplete="init()">

<s:layout>

<s:VerticalLayout/>

</s:layout>

<fx:Script>

<![CDATA[

import flash.text.engine.FontWeight;

import flashx.textLayout.conversion.TextConverter;

import flashx.textLayout.elements.ParagraphElement;

import flashx.textLayout.elements.TextFlow;

import spark.utils.TextFlowUtil;

private var hi:String="my code"

private var cnt:int=10;

var markup:String="hello";

private var text:TextFlow;

private var levelName:String = "family"

public function init()

{

trace("here");

markup += "world";

if(levelName == "family"){

markup +="<span fontSize='15' color='#ff0000' fontFamily='Verdana'>"+ hi + "</span> (<span fontSize='12' color='#007fc5' fontFamily='Arial'>"+cnt+") > </span>";

trace("string::"+markup)

}

text=TextFlowUtil.importFromString(markup,TextConverter.TEXT_FIELD_HTML_FORMAT);

}

private function clickBtn(event:MouseEvent):void{

markup += "world";

if(levelName == "family"){

markup +="<span fontSize='15' color='#ff0000' fontFamily='Verdana'>"+ hi + "</span> (<span fontSize='12' color='#007fc5' fontFamily='Arial'>"+cnt+") > </span>";

trace("string::"+markup)

}

rTxt1.textFlow =TextFlowUtil.importFromString(markup,TextConverter.TEXT_FIELD_HTML_FORMAT);

}

]]>

</fx:Script>

<s:RichText>

Hello

<s:span fontSize='16'>BIG NEW</s:span>

World!

</s:RichText>

<!-- Or the TextFlow child tag. -->

<s:RichText id="rTxt" textFlow="{text}"/>

<s:RichText id="rTxt1" />

<s:Button click="clickBtn(event)" label="Click"/>

</s:Application>

Adobe Employee
June 30, 2011

Replace the line

rTxt1.textFlow =TextFlowUtil.importFromString(markup,TextConverter.TEXT_FIELD_HTML_F ORMAT);

with

var imp:ITextImporter = TextConverter.getImporter(TextConverter.TEXT_FIELD_HTML_FORMAT);
rTxt1.textFlow = imp.importToFlow(markup);


Then your code will work.

flashx.textLayout.convertion.TextConverter is the converter in TLF, which work well. TextFlowUtil is not under our control.

Known Participant
July 1, 2011

Is the result OK for you after you run the code as follows?

<?xml version="1.0" encoding="utf-8"?>

<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
               xmlns:mx="library://ns.adobe.com/flex/mx"
               xmlns:s="library://ns.adobe.com/flex/spark"
               creationComplete="init()">
    <s:layout>
        <s:VerticalLayout/>
    </s:layout>
    <fx:Script>

        <![CDATA[
            import flash.text.engine.FontWeight;
            import flashx.textLayout.conversion.*;
            import flashx.textLayout.elements.ParagraphElement;
            import flashx.textLayout.elements.TextFlow;
            import spark.utils.TextFlowUtil;
            private var hi:String="my code"
            private var cnt:int=10;
            var markup:String="hello";
            [Bindable]
            private var text:TextFlow;
            private var levelName:String = "family"
            public function init()
            {
                trace("here");
                markup += "world";
                if(levelName == "family"){
                    markup +="<span fontSize='15' color='#ff0000' fontFamily='Verdana'>"+ hi + "</span> (<span fontSize='12' color='#007fc5' fontFamily='Arial'>"+cnt+") > </span>";
                    trace("string::"+markup)
                }
                text = TextFlowUtil.importFromString(markup,TextConverter.TEXT_FIELD_HTML_FORMAT);
            }
           
            private function clickBtn(event:MouseEvent):void{
                markup += "world";
                if(levelName == "family"){
                    markup +="<span fontSize='15' color='#ff0000' fontFamily='Verdana'>"+ hi + "</span> (<span fontSize='12' color='#007fc5' fontFamily='Arial'>"+cnt+") > </span>";
                    trace("string::"+markup)
                }
                rTxt1.textFlow =TextFlowUtil.importFromString(markup,TextConverter.TEXT_FIELD_HTML_FORMAT);
            }
        ]]>
       
    </fx:Script>
    <s:RichText>
        Hello
        <s:span fontSize="16">BIG NEW</s:span>
        World!
    </s:RichText>
    <!-- Or the TextFlow child tag. -->
    <s:RichText id="rTxt" textFlow="{text}"/>
    <s:RichEditableText id="rTxt1"/>
    <s:Button label="Click" click="clickBtn(event)"/>
</s:Application>


Thanks a Jin, its working fine now.

I found one more way of doing the same, please have a look below:

<?xml version="1.0" encoding="utf-8"?>

<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"

   xmlns:mx="library://ns.adobe.com/flex/mx"

   xmlns:s="library://ns.adobe.com/flex/spark"

   creationComplete="init()">

<s:layout>

<s:VerticalLayout/>

</s:layout>

<fx:Script>

<![CDATA[

import flashx.textLayout.conversion.ITextImporter;

import flashx.textLayout.conversion.TextConverter;

import flashx.textLayout.elements.TextFlow;

import spark.utils.TextFlowUtil;

[Bindable]

private var textFlowTxt:TextFlow;

private var hi:String="my code"

private var cnt:int=10;

private var markup:String="hello";

private var levelName:String = "family";

private function createTextFlow():TextFlow {

var htmlText:String = "<span fontSize='15' color='#ff0000' fontFamily='Verdana'>"+ hi + "</span> (<span fontSize='12' color='#007fc5' fontFamily='Arial'>"+cnt+") > </span>";

var textFlow:TextFlow = TextFlowUtil.importFromString(htmlText, TextConverter.TEXT_FIELD_HTML_FORMAT );

return textFlow;

}

]]>

</fx:Script>

<s:RichText>

Hello

<s:span fontSize='16'>BIG NEW</s:span>

World!

</s:RichText>

<!-- Or the TextFlow child tag. -->

<s:RichText id="rTxt" textFlow="{createTextFlow()}"/>

</s:Application>

Adobe Employee
November 10, 2010

I can reproduce this in TLF 2.0 and filed a bug.  I did observe that if I click on textFlow2 the link begins to work.  What version of TLF are you using?

Thanks,

Richard

Known Participant
November 11, 2010

Thanks for the reply

I am using flex sdk 4.1 bundled version.I don't know which version exactly, is that 1.1?

is there a way to workaround ? If I switch to tlf2.0 or newer version the problem might gone?

Adobe Employee
November 11, 2010

Yes - Flex 4.1 is using TLF 1.1.  Thanks.

I have fixed this in 2.0.  For a 1.1 workaround you can do this:

<?xml version="1.0" encoding="utf-8"?>


<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
                           xmlns:s="library://ns.adobe.com/flex/spark" 
                           xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="400" minHeight="300">
        <s:layout>
                <s:BasicLayout/>
        </s:layout>
        <fx:Script>
                <![CDATA[
                    import flashx.textLayout.compose.StandardFlowComposer;
                    import flashx.textLayout.elements.LinkElement;
                    import flashx.textLayout.elements.ParagraphElement;
                    import flashx.textLayout.elements.SpanElement;
                    import flashx.textLayout.elements.TextFlow;
                    import mx.core.mx_internal;
                    import flashx.textLayout.tlf_internal;

                        [Bindable] public var textFlow:TextFlow = new TextFlow();
                      
                        [Bindable] public var textFlow2:TextFlow = new TextFlow();
              
                              
                        protected function button1_clickHandler(event:MouseEvent):void
                        {
                                ret2.mx_internal::textContainerManager.tlf_internal::convertToTextFlowWithComposer();                               
                                textFlow2.addChild(getElement());
                              
                              
                                ret.mx_internal::textContainerManager.tlf_internal::convertToTextFlowWithComposer();
                                textFlow.addChild(getElement());
                         }

                        private function getElement():ParagraphElement{
                                var linkSpan:SpanElement = new SpanElement();
                                linkSpan.text = "link";
                                var link:LinkElement = new LinkElement();
                                link.addChild(linkSpan);
                                link.href = "http://www.adobe.com"
                                var p:ParagraphElement = new ParagraphElement();
                                p.addChild(link);
                                return p;
                        }       
                ]]>
        </fx:Script>
        <fx:Declarations>
                <!-- -->
        </fx:Declarations>
        <s:RichEditableText id="ret2" editable="false" text="RichText" width="180" height="165"  textFlow="{textFlow2}" />
        <s:RichEditableText id="ret" editable="false" x="196"   text="RichText" width="180" height="165" textFlow="{textFlow}" />
        <s:Button x="116" y="217" label="button" click="button1_clickHandler(event)"/>
</s:Application>