2 Replies Latest reply on Apr 26, 2011 10:00 AM by EricJ32

    Using an <a click=""> in RichEditableText

    EricJ32 Level 1

      Hi,

       

      I need to have a RichEditableText control which has a link in the middle of the text. On clicking this link, a function is called, rather than a traditional href.

       

      Originally, this looked like:

       

      <s:RichEditableText width="100%"

      selectable="false"

      editable="false">

      <s:span>This is my text and if I </s:span>

      <s:a click="linkClickHandler(event)">click here</s:a>

      <s:span> then it runs a local method</s:span>

      </s:RichEditableText>

       

      with the function as:

       

      protected function linkClickHandler(event:FlowElementMouseEvent):void

      {

         Alert.show("clicked");

      }

       

      However, now I need to load the text at runtime. For normal text, I can use the TextFlowUtil.importFromString() method to convert it, but this doesn't work with the clickable anchor.

       

      Can anyone shed some light on how I should do this?

       

      Thanks

        • 1. Re: Using an <a click=""> in RichEditableText
          FTQuest Level 3

          You can put your text in xml, download it at runtime, and then everything would work in the same way; i.e. using FlowElementMouseEvent.CLICK.

           

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

           

          <TextFlow version="2.0.0" xmlns="http://ns.adobe.com/textLayout/2008" >

          <p>

          Lorem ipsum dolor sit amet, consectetur adipiscing elit.

              <a href='event:yourCustomClick'>Quisque tempus</a>, eros ac dignissim interdum, elit sem euismod velit, eget laoreet urna metus nec enim.

          </p>

          </TextFlow>

           

          HTH,

          FTQuest

          1 person found this helpful
          • 2. Re: Using an <a click=""> in RichEditableText
            EricJ32 Level 1

            Thanks, that pointed me in the right direction. My problem was that the method wasn't being called. I didn't need to put it into an XML file; the resource file I was using was fine, along with a TextFlowUtil.importFromString call.

             

            For completion's sake, here's my solution:

             

            The trick was to add an event listener on creationComplete for the particular click event:

             

            private function creationComplete(event:FlexEvent):void

            {

                 richText.textFlow.addEventListener("myCustomClick", customClickHandler);

            }

             

            private function customClickHandler(event:FlowElementMouseEvent):void

            {   

                 Alert.show("hi");

            }

             

            <s:RichEditableText selectable="false" editable="false" textFlow="{textWithLink}" />

             

            where "textWithLink" looked like:

             

            <span>This is my custom text with a </span> <a href="event:myCustomClick">clickable link</a>