polyGeek.com
polyGeek.com

Automatically getting underlined links in the RichTextEditor

December 2nd, 2008 . by polygeek

From the livedocs documentation on the RichTextEditor:

To create a link, select a range of text, enter the link target in the text box on the right, and press Enter. You can only specify the URL; the link always opens in a _blank target. Also, creating the link does not change the appearance of the link text; you must separately apply any color and underlining.

I wanted the links to appear underlined in the comment submission form that I created for polyGeek.com – see below. I think it’s poor usability to have a RichTextEditor that makes links but doesn’t underline them. The user is left wondering if the link work or not.

Adding the underline was pretty easy. All it took was a suitable application of Regular Expressions. Take a look at the two RTEs below. The top one is your regular old RTE and the bottom one is customized to display underlined links.

view source

If you work with the RichTextEditor you’ll learn real quick that it isn’t like your other Flex Components. At first glance you would think that the following code would give you the HTMLtext in of the RTE:

var html:String = rte.htmlText;

But no. The rte itself doesn’t have a property for htmlText. That’s because the RTE is really a Panel filled with other components, like a TextArea. So if you want the htmlText you would say:

var html:String = rte.textArea.htmlText;

In retrospect this seems pretty obvious. It first confounded me because I set a FocusOut event listener on my RTE but it wouldn’t fire when the TextArea lost focus – which is what I wanted. After a few minutes of poking around I figured it out. Hopefully I’ve just saved you the grief.

To set listeners you should probably listen for the creationComplete event on your RTE. Then you can go and add listeners for which ever parts of the RTE you need to.

Share and Enjoy:
  • del.icio.us
  • Reddit
  • StumbleUpon
  • Technorati
  • Digg
  • Facebook
  • Slashdot

similar posts

5 Responses to “Automatically getting underlined links in the RichTextEditor”


comment number 1 by: Jason Langdon

The HTML the RTE creates is still pretty horendous. I don't know why Adobe hasn't cleaned up this part of the Flash Platform and try and make it adhere to the standards that Browsers now tend to be.

Here's a way to clean up your RTE generated code – http://thanksmister.com/?p=17

There's also a google code project for the component – http://code.google.com/p/flex-richtexteditor-html-utils/

On a tangent, I was playing around with the sounds on your comment component and noticed that focusing the mouse out of the textarea will make the end of line typewriter sound. I would've though it should make some form of power down sound, and that hitting the enter key would make the EOL sound? Not that I have the sound on anyways ;-)

comment number 2 by: polyGeek

@Jason, no kidding. I did a lot of RegEx work on the HTML code for the CommentSubmitter here on polyGeek. Don't need a lot of that crap in there.

Thanks for the links. I'll check'em out.

I sort of dropped the ball on the Sound thingy. Everyone hated it so I turned it off by default and didn't flesh it out. I think the typewriter-return plays anytime a field loses focus. You're right, a nice door sound for StarWars would fit right in with the old typewriting sounds. :)

comment number 3 by: sydd

Nice work, it has a problem tho:

If you make some text a link underlines it.

BUT if you select that text again and change the link it removes the underline :(

comment number 4 by: polyGeek

@sydd, thanks for pointing that out. I'll put it on the 2Do list.

comment number 5 by: Don

Thank you so much! This was driving users crazy…so I really appreciate you sharing it!

Don Kerr

comment number 6 by: Armen

@polyGeek Thx for the solution.

I find a simple way to fix the bug posted by @sydd

//store last changed link

private var _lastlink:String;

//add change event to see when link is changing (inside rteCustomizedInit())

body.linkTextInput.addEventListener(Event.CHANGE,onLinkChange);

private function onLinkChange(e:Event):void

{

_lastlink = body.linkTextInput.text;

}

//and change the last lines of onLinkFocusOut()

// checking if link is set and is not selected then underline, otherwise if not link //and underline exist remove underline

if(!body.underlineButton.selected)

{

if(_lastlink !== "http://" && _lastlink !==null)

body.underlineButton.dispatchEvent( new MouseEvent( MouseEvent.CLICK, false ) );

}else

{

if(_lastlink == "http://" || _lastlink =="")

body.underlineButton.dispatchEvent( new MouseEvent( MouseEvent.CLICK, false ) );

}

comment number 7 by: polyGeek

@Armen, wow, thanks for all the code. That really helps.

   Welcome back (Change)

Leave a Reply

comment feed RSS   subscribe to this comment thread

Recent Posts

   




© Copyright 2008 polyGeek.com / Dan Florio, All Rights Reserved Except Where Explicitly Stated
Web Developement Blogs - Blog Catalog Blog Directory
Ajax CommentLuv Enabled 816cf46662e57ab1b89821d8e1e32a6b
M2 Websites
Local Directory for Los Angeles, CA