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 = ""
var cssEnd = ""
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 = "" + sF +
"";
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