开发者

Flex, link in RichEditableText's textFlow isn't clickable if width is set and text is aligned center

so I have following code.

    <fx:Script>
        <![CDATA[
            import flashx.textLayout.conversion.TextConverter;
            private var stringWithLink : String = "click for some event<a href='event:foobar'>foobar 012345647890123456789</a>";
        ]]>
    </fx:Script>

    <s:RichEditableText id="text1" editable="false"  selectable="false" left="0" right="0" textAlign="center"
                        textFlow="{TextConverter.importToFlow(stringWithLink, TextConverter开发者_运维百科.TEXT_FIELD_HTML_FORMAT)}" />

</s:WindowedApplication>

there is one RichEditableText (text1) with html text with href that generate some event(foobar). Problem is the part of the link is not working. for the sake of simplicity, i didn't include the code to catch event from the textFlow, but you can tell that the link is not working because mouse cursor won't turn to hand cursor for the first part of the link. From beginning of the link to around first 9, the mouse cursor will stay as pointer but if you move your mouse past the first 9, the cursor will change to hand cursor. If you remove the numeric part of the string, the whole link stop responding.

This seems like a problem with width and text align. If you don't define width on text1, the problem goes away. but if you define fixed width or percentage width, the problem comes back. I also tried different text alignment. If you try any alignment that will align the text to the left (start, justify, left), it works correctly. But if you use alignment that will align text away from the left edge (center, right, end), the problem comes back.

anyone have any idea why this might be happening? any solutions?


I ran into the same problem. Not sure why it's happening. I did find a solution though. It does have the one drawback of making the entire text field clickable instead of just the URL. In my application, I am dynamically creating flex UI objects on the fly from XML. So I already have the HTML string and the text alignment handy.

//htmlText - html string pulled from the xml
//align - text alignment from xml
//txt - RichEditableText object

if ((htmlText.search(/<a *href/g) >= 0) && (align.toLowerCase() != 'left')) {
    txt.textFlow.addEventListener(FlowElementMouseEvent.MOUSE_MOVE, useMouseHand);
    txt.addEventListener(MouseEvent.CLICK, urlClickHandler);
    txt.addEventListener(MouseEvent.MOUSE_OVER, useMouseHand);
}

The function useMouseHand has one statement: Mouse.cursor = MouseCursor.BUTTON;

The function urlClickHandler parses the htmlText for the href and target values and calls navigateToURL (flash.net.navigateToURL).

As far as the event listeners, I found I had to have both the textflow and RichEditableText mouse over/move handlers going to get the hand cursor to show.

Hope that helps.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜