<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Find Cursor Position in a HtmlText Object (RichTextEditor, TextArea, TextField) &#8211; UPDATE</title>
	<atom:link href="http://www.flexer.info/2008/03/26/find-cursor-position-in-a-htmltext-object-richtexteditor-textarea-textfield-update/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.flexer.info/2008/03/26/find-cursor-position-in-a-htmltext-object-richtexteditor-textarea-textfield-update/</link>
	<description>flex developers web corner</description>
	<lastBuildDate>Wed, 18 Jan 2012 13:28:25 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=abc</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Ian Davies</title>
		<link>http://www.flexer.info/2008/03/26/find-cursor-position-in-a-htmltext-object-richtexteditor-textarea-textfield-update/comment-page-1/#comment-1975</link>
		<dc:creator>Ian Davies</dc:creator>
		<pubDate>Fri, 01 Oct 2010 21:06:41 +0000</pubDate>
		<guid isPermaLink="false">http://www.flexer.info/2008/03/26/find-cursor-position-in-a-htmltext-object-richtexteditor-textarea-textfield-update/#comment-1975</guid>
		<description>Hey,
you can get rid of the function if you use the internal namespace for the textArea - where all you want to do is insert new text.
&lt;pre lang=&quot;actionscript&quot;&gt;(myRichTextComponentInstance.textArea.mx_internal::getTextField() as TextField).replaceSelectedText( &quot;Your new Text&quot; );&lt;/pre&gt;

Regards
Ian</description>
		<content:encoded><![CDATA[<p>Hey,<br />
you can get rid of the function if you use the internal namespace for the textArea &#8211; where all you want to do is insert new text.</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #66cc66;">&#40;</span>myRichTextComponentInstance.<span style="color: #006600;">textArea</span>.<span style="color: #006600;">mx_internal</span>::getTextField<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> as <span style="color: #0066CC;">TextField</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">replaceSelectedText</span><span style="color: #66cc66;">&#40;</span> <span style="color: #ff0000;">&quot;Your new Text&quot;</span> <span style="color: #66cc66;">&#41;</span>;</pre></div></div>

<p>Regards<br />
Ian</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Andrei Ionescu</title>
		<link>http://www.flexer.info/2008/03/26/find-cursor-position-in-a-htmltext-object-richtexteditor-textarea-textfield-update/comment-page-1/#comment-1747</link>
		<dc:creator>Andrei Ionescu</dc:creator>
		<pubDate>Sat, 14 Nov 2009 06:41:14 +0000</pubDate>
		<guid isPermaLink="false">http://www.flexer.info/2008/03/26/find-cursor-position-in-a-htmltext-object-richtexteditor-textarea-textfield-update/#comment-1747</guid>
		<description>Chuck, thanks for sharing that nice piece of code with us. Great job!</description>
		<content:encoded><![CDATA[<p>Chuck, thanks for sharing that nice piece of code with us. Great job!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Chuck Simpson</title>
		<link>http://www.flexer.info/2008/03/26/find-cursor-position-in-a-htmltext-object-richtexteditor-textarea-textfield-update/comment-page-1/#comment-1746</link>
		<dc:creator>Chuck Simpson</dc:creator>
		<pubDate>Fri, 13 Nov 2009 22:44:21 +0000</pubDate>
		<guid isPermaLink="false">http://www.flexer.info/2008/03/26/find-cursor-position-in-a-htmltext-object-richtexteditor-textarea-textfield-update/#comment-1746</guid>
		<description>I refactored the code and added the list item tag as a line breaking tag.

&lt;pre lang=&quot;actionscript&quot;&gt;private var endtag:String;
private var tagMatcher:Object = {&quot;&lt;&quot;:&quot;&gt;&quot;, &quot;&amp;&quot;:&quot;;&quot;};
private var tagLength:Object = {&quot;&gt;&quot;:0, &quot;;&quot;:1};
private var breakingTags:Object = {&quot;&lt;/LI&gt;&quot;:&quot;1&quot;, &quot;&lt;/P&gt;&quot;:&quot;1&quot;, &quot;&lt;BR&gt;&quot;:&quot;1&quot;};
private var tagContent:String = &quot;&quot;;
    
private function getCharCount(c:String):int {
    var count:int = 1;
    endtag = endtag == null ? tagMatcher[c] : endtag;
    if(endtag != null) {
        tagContent += c;
        count = 0;
        if (endtag == c) {
            count = tagLength[endtag];
            endtag = null;
            if (breakingTags[tagContent] != null) {
                count++;
            }
            tagContent = &quot;&quot;;
        }
    }
    return count;
}
    
public function calculateHtmlPosition(htmlstr:String, position:int):int {
    var i:int = -1;
    if (position &gt;= 0) {  
        var count:int = 0;     
        for (i = 0; i &lt; htmlstr.length; i++) {
            if (count &gt;= position) {
                return i;
            }
            count += getCharCount(htmlstr.charAt(i));
        }
    }
    return i;
}&lt;/pre&gt;</description>
		<content:encoded><![CDATA[<p>I refactored the code and added the list item tag as a line breaking tag.</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> endtag:<span style="color: #0066CC;">String</span>;
<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> tagMatcher:<span style="color: #0066CC;">Object</span> = <span style="color: #66cc66;">&#123;</span><span style="color: #ff0000;">&quot;&amp;lt;&quot;</span>:<span style="color: #ff0000;">&quot;&amp;gt;&quot;</span>, <span style="color: #ff0000;">&quot;&amp;amp;&quot;</span>:<span style="color: #ff0000;">&quot;;&quot;</span><span style="color: #66cc66;">&#125;</span>;
<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> tagLength:<span style="color: #0066CC;">Object</span> = <span style="color: #66cc66;">&#123;</span><span style="color: #ff0000;">&quot;&amp;gt;&quot;</span>:<span style="color: #cc66cc;">0</span>, <span style="color: #ff0000;">&quot;;&quot;</span>:<span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#125;</span>;
<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> breakingTags:<span style="color: #0066CC;">Object</span> = <span style="color: #66cc66;">&#123;</span><span style="color: #ff0000;">&quot;&amp;lt;/LI&amp;gt;&quot;</span>:<span style="color: #ff0000;">&quot;1&quot;</span>, <span style="color: #ff0000;">&quot;&amp;lt;/P&amp;gt;&quot;</span>:<span style="color: #ff0000;">&quot;1&quot;</span>, <span style="color: #ff0000;">&quot;&amp;lt;BR&amp;gt;&quot;</span>:<span style="color: #ff0000;">&quot;1&quot;</span><span style="color: #66cc66;">&#125;</span>;
<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> tagContent:<span style="color: #0066CC;">String</span> = <span style="color: #ff0000;">&quot;&quot;</span>;
&nbsp;
<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> getCharCount<span style="color: #66cc66;">&#40;</span>c:<span style="color: #0066CC;">String</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">int</span> <span style="color: #66cc66;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">var</span> count:<span style="color: #0066CC;">int</span> = <span style="color: #cc66cc;">1</span>;
    endtag = endtag == <span style="color: #000000; font-weight: bold;">null</span> ? tagMatcher<span style="color: #66cc66;">&#91;</span>c<span style="color: #66cc66;">&#93;</span> : endtag;
    <span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span>endtag <span style="color: #66cc66;">!</span>= <span style="color: #000000; font-weight: bold;">null</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
        tagContent += c;
        count = <span style="color: #cc66cc;">0</span>;
        <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>endtag == c<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
            count = tagLength<span style="color: #66cc66;">&#91;</span>endtag<span style="color: #66cc66;">&#93;</span>;
            endtag = <span style="color: #000000; font-weight: bold;">null</span>;
            <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>breakingTags<span style="color: #66cc66;">&#91;</span>tagContent<span style="color: #66cc66;">&#93;</span> <span style="color: #66cc66;">!</span>= <span style="color: #000000; font-weight: bold;">null</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
                count++;
            <span style="color: #66cc66;">&#125;</span>
            tagContent = <span style="color: #ff0000;">&quot;&quot;</span>;
        <span style="color: #66cc66;">&#125;</span>
    <span style="color: #66cc66;">&#125;</span>
    <span style="color: #b1b100;">return</span> count;
<span style="color: #66cc66;">&#125;</span>
&nbsp;
<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> calculateHtmlPosition<span style="color: #66cc66;">&#40;</span>htmlstr:<span style="color: #0066CC;">String</span>, <span style="color: #0066CC;">position</span>:<span style="color: #0066CC;">int</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">int</span> <span style="color: #66cc66;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">var</span> i:<span style="color: #0066CC;">int</span> = -<span style="color: #cc66cc;">1</span>;
    <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">position</span> <span style="color: #66cc66;">&amp;</span>gt;= <span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>  
        <span style="color: #000000; font-weight: bold;">var</span> count:<span style="color: #0066CC;">int</span> = <span style="color: #cc66cc;">0</span>;     
        <span style="color: #b1b100;">for</span> <span style="color: #66cc66;">&#40;</span>i = <span style="color: #cc66cc;">0</span>; i <span style="color: #66cc66;">&amp;</span>lt; htmlstr.<span style="color: #0066CC;">length</span>; i++<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
            <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>count <span style="color: #66cc66;">&amp;</span>gt;= <span style="color: #0066CC;">position</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
                <span style="color: #b1b100;">return</span> i;
            <span style="color: #66cc66;">&#125;</span>
            count += getCharCount<span style="color: #66cc66;">&#40;</span>htmlstr.<span style="color: #0066CC;">charAt</span><span style="color: #66cc66;">&#40;</span>i<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
        <span style="color: #66cc66;">&#125;</span>
    <span style="color: #66cc66;">&#125;</span>
    <span style="color: #b1b100;">return</span> i;
<span style="color: #66cc66;">&#125;</span></pre></div></div>

]]></content:encoded>
	</item>
	<item>
		<title>By: Ken</title>
		<link>http://www.flexer.info/2008/03/26/find-cursor-position-in-a-htmltext-object-richtexteditor-textarea-textfield-update/comment-page-1/#comment-1729</link>
		<dc:creator>Ken</dc:creator>
		<pubDate>Wed, 14 Oct 2009 06:26:42 +0000</pubDate>
		<guid isPermaLink="false">http://www.flexer.info/2008/03/26/find-cursor-position-in-a-htmltext-object-richtexteditor-textarea-textfield-update/#comment-1729</guid>
		<description>For adding something like a copyright or registration symbol I just use
&lt;pre lang=&quot;actionscript&quot;&gt;private function addMark(v:String):void
{
    rte.selection.htmlText = v;
    rte.selection.beginIndex++;	
}&lt;/pre&gt;

Then I just call the method sending the html I want inserted.


</description>
		<content:encoded><![CDATA[<p>For adding something like a copyright or registration symbol I just use</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> addMark<span style="color: #66cc66;">&#40;</span>v:<span style="color: #0066CC;">String</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
<span style="color: #66cc66;">&#123;</span>
    rte.<span style="color: #0066CC;">selection</span>.<span style="color: #0066CC;">htmlText</span> = v;
    rte.<span style="color: #0066CC;">selection</span>.<span style="color: #006600;">beginIndex</span>++;	
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p>Then I just call the method sending the html I want inserted.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Andrei Ionescu</title>
		<link>http://www.flexer.info/2008/03/26/find-cursor-position-in-a-htmltext-object-richtexteditor-textarea-textfield-update/comment-page-1/#comment-1667</link>
		<dc:creator>Andrei Ionescu</dc:creator>
		<pubDate>Mon, 27 Jul 2009 17:14:39 +0000</pubDate>
		<guid isPermaLink="false">http://www.flexer.info/2008/03/26/find-cursor-position-in-a-htmltext-object-richtexteditor-textarea-textfield-update/#comment-1667</guid>
		<description>Thanks Ahmad. Great job!</description>
		<content:encoded><![CDATA[<p>Thanks Ahmad. Great job!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ahmad Hamid</title>
		<link>http://www.flexer.info/2008/03/26/find-cursor-position-in-a-htmltext-object-richtexteditor-textarea-textfield-update/comment-page-1/#comment-1666</link>
		<dc:creator>Ahmad Hamid</dc:creator>
		<pubDate>Mon, 27 Jul 2009 12:34:34 +0000</pubDate>
		<guid isPermaLink="false">http://www.flexer.info/2008/03/26/find-cursor-position-in-a-htmltext-object-richtexteditor-textarea-textfield-update/#comment-1666</guid>
		<description>ah well I have both functions html-to-text and text-to-html as part of my spellcheck/trackchanges highlight code.  You can find it in the Highlighter.as class at the end.
http://flexbuzz.blogspot.com/2009/07/flex-textarea-track-changes-highlight.html</description>
		<content:encoded><![CDATA[<p>ah well I have both functions html-to-text and text-to-html as part of my spellcheck/trackchanges highlight code.  You can find it in the Highlighter.as class at the end.<br />
<a href="http://flexbuzz.blogspot.com/2009/07/flex-textarea-track-changes-highlight.html" rel="nofollow">http://flexbuzz.blogspot.com/2009/07/flex-textarea-track-changes-highlight.html</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ahmad Hamid</title>
		<link>http://www.flexer.info/2008/03/26/find-cursor-position-in-a-htmltext-object-richtexteditor-textarea-textfield-update/comment-page-1/#comment-1664</link>
		<dc:creator>Ahmad Hamid</dc:creator>
		<pubDate>Thu, 23 Jul 2009 14:10:49 +0000</pubDate>
		<guid isPermaLink="false">http://www.flexer.info/2008/03/26/find-cursor-position-in-a-htmltext-object-richtexteditor-textarea-textfield-update/#comment-1664</guid>
		<description>Hey, 
I rewrote the function using regular expressions to convert html to tokens of tags , entities and text before searching for the index in html.  I posted the function at 
&lt;a href=&quot;http://flexbuzz.blogspot.com/2009/07/text-index-to-html-index-conversion.html&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;http://flexbuzz.blogspot.com/2009/07/text-index-to-html-index-conversion.html&lt;/a&gt;</description>
		<content:encoded><![CDATA[<p>Hey,<br />
I rewrote the function using regular expressions to convert html to tokens of tags , entities and text before searching for the index in html.  I posted the function at<br />
<a href="http://flexbuzz.blogspot.com/2009/07/text-index-to-html-index-conversion.html" target="_blank" rel="nofollow">http://flexbuzz.blogspot.com/2009/07/text-index-to-html-index-conversion.html</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Tomer</title>
		<link>http://www.flexer.info/2008/03/26/find-cursor-position-in-a-htmltext-object-richtexteditor-textarea-textfield-update/comment-page-1/#comment-1633</link>
		<dc:creator>Tomer</dc:creator>
		<pubDate>Sun, 21 Jun 2009 12:40:28 +0000</pubDate>
		<guid isPermaLink="false">http://www.flexer.info/2008/03/26/find-cursor-position-in-a-htmltext-object-richtexteditor-textarea-textfield-update/#comment-1633</guid>
		<description>This is great, thanks :D.

Is there also a way then to do the vise-versa, find the text position of a htmlText place?</description>
		<content:encoded><![CDATA[<p>This is great, thanks <img src='http://www.flexer.info/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /> .</p>
<p>Is there also a way then to do the vise-versa, find the text position of a htmlText place?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ad</title>
		<link>http://www.flexer.info/2008/03/26/find-cursor-position-in-a-htmltext-object-richtexteditor-textarea-textfield-update/comment-page-1/#comment-1615</link>
		<dc:creator>Ad</dc:creator>
		<pubDate>Mon, 25 May 2009 17:32:54 +0000</pubDate>
		<guid isPermaLink="false">http://www.flexer.info/2008/03/26/find-cursor-position-in-a-htmltext-object-richtexteditor-textarea-textfield-update/#comment-1615</guid>
		<description>I had a bug because of a semicolon in my text ! 

I found a solution : 
(at the end of the code)

&lt;pre lang=&quot;actionscript&quot;&gt;
//...
else {
tagContent += currentChar;
// } &lt;== Just by mooving that brace
if (currentChar == closeTags[tagId]) {
...
}
} // &lt;== HERE
&lt;/pre&gt;

I hope it will not break anything else... It seems to be ok.</description>
		<content:encoded><![CDATA[<p>I had a bug because of a semicolon in my text ! </p>
<p>I found a solution :<br />
(at the end of the code)</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">//...</span>
<span style="color: #b1b100;">else</span> <span style="color: #66cc66;">&#123;</span>
tagContent += currentChar;
<span style="color: #808080; font-style: italic;">// } &amp;lt;== Just by mooving that brace</span>
<span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>currentChar == closeTags<span style="color: #66cc66;">&#91;</span>tagId<span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
...
<span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span> <span style="color: #808080; font-style: italic;">// &amp;lt;== HERE</span></pre></div></div>

<p>I hope it will not break anything else&#8230; It seems to be ok.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Romulo</title>
		<link>http://www.flexer.info/2008/03/26/find-cursor-position-in-a-htmltext-object-richtexteditor-textarea-textfield-update/comment-page-1/#comment-1578</link>
		<dc:creator>Romulo</dc:creator>
		<pubDate>Thu, 09 Apr 2009 15:41:04 +0000</pubDate>
		<guid isPermaLink="false">http://www.flexer.info/2008/03/26/find-cursor-position-in-a-htmltext-object-richtexteditor-textarea-textfield-update/#comment-1578</guid>
		<description>excelent work there Andrei! 
i´ve recently developed a kind of auto complete inside an textarea (in html/js) and now im trying to do the same on flex. Your script will help a lot in the development, but there is still one part missing. 

In order to correctly position the suggestion list i need to find the position (x,y) of the word relative to the textarea. You know a way to get it? Thanks in advance.

Keep the good job up!</description>
		<content:encoded><![CDATA[<p>excelent work there Andrei!<br />
i´ve recently developed a kind of auto complete inside an textarea (in html/js) and now im trying to do the same on flex. Your script will help a lot in the development, but there is still one part missing. </p>
<p>In order to correctly position the suggestion list i need to find the position (x,y) of the word relative to the textarea. You know a way to get it? Thanks in advance.</p>
<p>Keep the good job up!</p>
]]></content:encoded>
	</item>
</channel>
</rss>

