Getting selected text

Hi,

Is there any way to make flash return what text you have selected?

Say I have a textbox, with a bunch of text in it. I want to be able to highlight a word, and click a button and make the highlighted text capitals? I know there is a replace selected text function, but how can I work out what text is actually selected?

Any ideas anyone?