1

Given the following:

private var errorHtml:String = "<TextFlow xmlns=\"http://ns.adobe.com/textLayout/2008\"><p>Existing account, please <a click=\"clickHandler(event);\">click here</a>.</p></TextFlow>";

Then importing it on creationComplete:

errorMessageText.textFlow = TextConverter.importToFlow(errorHtml, TextConverter.TEXT_LAYOUT_FORMAT);

The click handler function never fires. But if I add it directly to the markup:

<s:textFlow>
  <s:TextFlow>
    <s:p>
        Existing account, please <a click=\"clickHandler(event);\">click here</a>.
    </s:p>
  </s:TextFlow>
</s:textFlow>

The event fires fine. I saw that these events get removed if you try to import as TEXT_FIELD_HTML_FORMAT:

Note: Unlike the TextField class, ActionScript link events are not supported. Neither are a:link, a:hover, and a:active styles.

Are they also removed using TEXT_LAYOUT_FORMAT?

Tony Smith
  • 869
  • 1
  • 11
  • 25

1 Answers1

1

Yea, it gets rid of all the 'FlowElementMouseEvent' events, annoying. Basically after importing you need to go back through and find all the links and then add FlowElementMouseEventhandlers. There's a blog post here: http://flexdevtips.blogspot.com/2010/10/displaying-html-text-in-labels.html which discusses how to do it.

Jonathan Rowny
  • 7,588
  • 1
  • 18
  • 26
  • Good lord. That is awful. Makes me want to just use MX components again. Thanks. – Tony Smith Jul 11 '11 at 20:27
  • Yea, I'm sure you can create a function that can do it pretty much automatically... the link I posted just adds one handler to one link which is kind of silly. In my opinion, I'd just make the anchor name the handler name then call it based on the anchor. – Jonathan Rowny Jul 11 '11 at 20:35
  • Yeah, I didn't use that code but I got what I needed to know. I ended up doing what you said and just added an event handler based on anchor ID: `(errorMessageText.textFlow.getElementByID("someLink") as LinkElement).addEventListener(FlowElementMouseEvent.CLICK, someLinkClickHandler);` – Tony Smith Jul 11 '11 at 21:17