[Flashcoders] search and replace keywords in textbox with CSS, asfunction.

2006-09-21 Thread Kurt Dommermuth

Hi All,

Earlier this week I asked about a function that could search through text, 
replace words that are selected from an array, and make them clickable.


Karian Steffens and Jason Merrill offered some good suggestions on how to 
do this (CSS/asfunction).


Below is something that works, but I'm sure could be better optimized...

Question though, the limits of CSS in flash are really bothersome.  No 
leading, no kerning?  geez.


I think I know the answer to this, but is there no way to apply flash's 
native text formatting on top of CSS ?


anyhow, the function (I would love help making it better). also, it 
requires a stylesheet...




//keywords array [[keyword, doThisOnPress]]
var keywords_ar:Array = new Array();
var keywords_ar:Array = 
[[biotechnology,_root.testfunc],[GM,_root.testfunc]];



//key word search
keyWordSearch = function(sTS)
{   
var len = keywords_ar.length-1;
var cssBegin = span class='generaltext'
var cssEnd = /span
for(i=len;i=0;i--)
{
var sF = _root.keywords_ar[i][0];
var func = _root.keywords_ar[i][1];
var startPos = sTS.indexOf(sF,0);
var marker = ? + i;
var falseMarker = ~ + i;
while(startPos != -1)
{
var startPos = sTS.indexOf(sF,0);
if(startPos == -1)
{
break;
}
var sLen = sF.length;
var endPos = sTS.indexOf(sF,startPos)+ sLen;
var cBefore = sTS.charAt(startPos-1);
var cAfter = sTS.charAt(endPos);
var beginText = sTS.substring(0,startPos);
var endText = sTS.substring(endPos,sTS.length);
if(cBefore ==   || cBefore ==  || cBefore == ()
{
if(cAfter == . || cAfter == , || cAfter == ; || cAfter == : || 
cAfter == ) || cAfter ==  )

{
sTS = beginText + marker + endText;
}
else
{
sTS = beginText + falseMarker + 
endText;
}
}
else
{
sTS = beginText + falseMarker + endText;

}
}
}
for(j=len;j=0;j--)
{
var sF = _root.keywords_ar[j][0];
var func = _root.keywords_ar[j][1];
var marker = ?+j;
var startPos = sTS.indexOf(marker,0);
while(startPos != -1)
{
var startPos = sTS.indexOf(marker,0);
if(startPos == -1)
{
break;
}
var sLen = marker.length;
var endPos = sTS.indexOf(marker,startPos)+ sLen;
var beginText = sTS.substring(0,startPos);
var endText = sTS.substring(endPos,sTS.length);
var replacement = a href=\'asfunction: + func + \' + sF + 
/a;
sTS = beginText + replacement + endText;
}
}
for(k=len;k=0;k--)
{
var sF = _root.keywords_ar[k][0];
var falseMarker = ~+k;
var startPos = sTS.indexOf(falseMarker,0);
while(startPos != -1)
{
var startPos = sTS.indexOf(falseMarker,0);
if(startPos == -1)
{
break;
}
var sLen = falseMarker.length;
var endPos = sTS.indexOf(falseMarker,startPos)+ sLen;
var beginText = sTS.substring(0,startPos);
var endText = sTS.substring(endPos,sTS.length);
var replacement = sF;
sTS = beginText + replacement + endText;
}
}   

return(cssBegin+sTS+cssEnd);
}

___
Flashcoders@chattyfig.figleaf.com
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com


Re: [Flashcoders] search and replace keywords in textbox with CSS, asfunction.

2006-09-21 Thread Iv
Hello Kurt,

about 2 years ago I did this:
http://www.sharedfonts.com/fla/as_highlight.fla
possible it can help you.

-- 
Ivan Dembicki

[EMAIL PROTECTED] || 
http://www.design.ru

___
Flashcoders@chattyfig.figleaf.com
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com


Re: [Flashcoders] search and replace keywords in textbox with CSS, asfunction.

2006-09-21 Thread Kurt Dommermuth

Now where the hell were you earlier this week!?

;)

that looks really cool and I bet much better written too, but I really need 
to make the highlighted text clickable.


I wanted to do that by getting the _x and _y of a given character, but I 
had no idea how.


that's why I went the html/css route so I could just add links and not care 
where the hell the _x and _y coords were.


Thanks Iv,
Kurt

At 12:39 PM 9/21/2006, you wrote:


Hello Kurt,

about 2 years ago I did this:
http://www.sharedfonts.com/fla/as_highlight.fla
possible it can help you.

--
Ivan Dembicki

[EMAIL PROTECTED] || 
http://www.design.ru

___
Flashcoders@chattyfig.figleaf.com
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com


___
Flashcoders@chattyfig.figleaf.com
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com