Skip navigation
davy zhang
Currently Being Moderated

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

Nov 10, 2010 2:05 AM

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>

 
Replies
  • Currently Being Moderated
    Nov 10, 2010 3:48 PM   in reply to davy zhang

    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

     
    |
    Mark as:
  • Currently Being Moderated
    Nov 11, 2010 2:33 PM   in reply to davy zhang

    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::convertToTextFlo wWithComposer();                               
                                    textFlow2.addChild(getElement());
                                  
                                  
                                    ret.mx_internal::textContainerManager.tlf_internal::convertToTextFlow WithComposer();
                                    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>
     
    |
    Mark as:
  • Currently Being Moderated
    Nov 12, 2010 10:28 AM   in reply to davy zhang

    My fix hasn't been posted to the TLF sourceforge site yet - there's a lag because we have to run a script that get's odd timeout errors. A separate 2.0 bug with scrolled links demonstrated by your example was fixed a couple of days ago - build 200 contains all these fixes.

     

    In your sample code the call to updateAllControllers can cause a RTE.  The textFlow in a RichEditableText is not guaranteed to have a flowComposer. Normally flex takes care of composing for you and that line can be removed.

     

    If you do want to force a compose use this function:

    ret.mx_internal::textContainerManager.updateContainer()

     

    BTW thanks for the code examples - they're much easier to follow than verbal descriptions.

     

    Hope that helps,

    Richard

     
    |
    Mark as:
  • Currently Being Moderated
    Nov 15, 2010 3:07 PM   in reply to davy zhang

    Can't comment about 4.5 dates beyond what's posted here:

    http://opensource.adobe.com/wiki/display/flexsdk/Hero

     

    Richard

     
    |
    Mark as:
  • Currently Being Moderated
    Jun 29, 2011 1:06 PM   in reply to davy zhang

    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_HTM L_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_F ORMAT);

    }

     

    ]]>

    </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>

     
    |
    Mark as:
  • Currently Being Moderated
    Jun 30, 2011 12:52 AM   in reply to kanukukreja

    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.

     
    |
    Mark as:
  • Currently Being Moderated
    Jun 30, 2011 1:15 AM   in reply to Jin-Huang

    Hi Jin,

     

    Thanks for the response, but its not working for me.

    Its not working for when i'm binding the value.. can you please once lok at it and helping me in resolving this issue.

     

    <?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.ITextImporter;

    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)

    }

    var imp:ITextImporter = TextConverter.getImporter(TextConverter.TEXT_FIELD_HTML_FORMAT);

    text = imp.importToFlow(markup); {Your code}

    //text=TextFlowUtil.importFromString(markup,TextConverter.TEXT_FIELD_H TML_FORMAT); {my code}

     

    }

     

    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_F ORMAT);

    }

    ]]>

    </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}"/> {not working this way}

    <s:RichText id="rTxt1" />

    <s:Button click="clickBtn(event)" label="Click"/> {Working this way}

    </s:Application>

     
    |
    Mark as:
  • Currently Being Moderated
    Jun 30, 2011 1:47 AM   in reply to kanukukreja

    [Bindable]
    private var text:TextFlow;

     

    Declare text as Bindable

     

     

    Besides, I found that two types of import show different results. Choose the one you like

     
    |
    Mark as:
  • Currently Being Moderated
    Jun 30, 2011 1:53 AM   in reply to Jin-Huang

    After binding i can see the text but without formatting...so my problem is still at the place from where i have started

     

    Am i missing anything?

     

    Message was edited by: kanukukreja

     
    |
    Mark as:
  • Currently Being Moderated
    Jun 30, 2011 1:59 AM   in reply to kanukukreja

    One more thing which i just noticed is that after removing textFlowUtil from the clickEvent, its also started showing the text without formatting.

     

    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)

    }

    var imp:ITextImporter = TextConverter.getImporter(TextConverter.TEXT_FIELD_HTML_FORMAT);

    rTxt1.textFlow = imp.importToFlow(markup);

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

    }

     
    |
    Mark as:
  • Currently Being Moderated
    Jun 30, 2011 2:11 AM   in reply to kanukukreja

    TextFlowUtil.importFromString will give you text with sytles, while  imp.importToFlow cannot. I will investigate if it's a TLF bug.

    (At the very beginning, TextFlowUtil.importFromString does not show any text, but importToFlow can. But now importFromString works. I'm not sure what's going on. My answer at #9 is wrong.)

     
    |
    Mark as:
  • Currently Being Moderated
    Jun 30, 2011 2:20 AM   in reply to Jin-Huang

    Thanks a ton Jin for the quick responses, please share if you find anything regarding the same.

     

    TextFlowUtil.importFromString will give you text with sytles, while  imp.importToFlow cannot. I will investigate if it's a TLF bug.

     

    >>> Let me know if you find any solution for the same.

     

    (At the very beginning, TextFlowUtil.importFromString does not show any text, but importToFlow can.

     

    >>> Only in the case of bindable textflow values otherwise it shows the formatted text.

     

    But now importFromString works. I'm not sure what's going on. My answer at #9 is wrong.)

     

    >>> importFromString still works but not with the bindable texts. Thats the only issue.

     

     
    |
    Mark as:
  • Currently Being Moderated
    Jun 30, 2011 2:40 AM   in reply to kanukukreja

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

     

    <?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_FO RMAT);
                }
               
                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_F ORMAT);
                }
            ]]>
           
        </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>

     
    |
    Mark as:
  • Currently Being Moderated
    Jun 30, 2011 11:36 PM   in reply to Jin-Huang

    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>

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points