|
|
|
#1 |
|
Registered User
Join Date: Mar 2010
Posts: 6
|
reading RTF encoded text in FLASH
I am using Swf Studio to read data from an Access database into Flash. The problem is some of the fields in the database contain RTF encoded text, so when I put the text into a text field in FLASH, it shows all the RTF code. Are there any Rich Text controls for Flash. I found something about the Spark Text Control in Flash builder but I am new to Flash Builder. Any guidance would be appreciated.
|
|
|
|
|
|
#2 |
|
Tim
Join Date: May 2001
Location: Ottawa
Posts: 11,873
|
Can you show us what the RTF you're dealing with looks like? It might be easy to strip out the RTF codes with regular expressions in AS3 if they aren't too complicated.
|
|
|
|
|
|
#3 |
|
Registered User
Join Date: Mar 2010
Posts: 6
|
Here is a sample field from the database:
{\rtf1\ansi\ansicpg1252\deff0{\fonttbl{\f0\fnil\fcharset0 Arial;}{\f1\fnil\fcharset0 Arial;}} {\colortbl ;\red0\green128\blue0;\red0\green0\blue0;} \viewkind4\uc1\pard\cf1\lang1033\i\f0\fs36 (ACTC3RSL1:Q13) \cf2\i0\fs48 Claude\rquote s attitude toward Jerry is one of\cf0\f1\fs41\par } The main problem is that they have a lot of text formatting in the database and they would really like it to have the same look in the flash program I am working on. Thanks. |
|
|
|
|
|
#4 |
|
Tim
Join Date: May 2001
Location: Ottawa
Posts: 11,873
|
Ohhhh, so you don't want to just strip the rtf codes out, you want to preserve the formatting. For that you will need some kind of rtf control or a converter.
|
|
|
|
|
|
#5 |
|
Registered User
Join Date: Mar 2010
Posts: 6
|
yes, I have researching but so far I have come up empty. Any ideas?
Thank you |
|
|
|
|
|
#6 |
|
Tim
Join Date: May 2001
Location: Ottawa
Posts: 11,873
|
Do you need to modify the RTF field and save it back to the database or is this going to be a one way operation where you just need to display it?
|
|
|
|
|
|
#7 | |
|
Tim
Join Date: May 2001
Location: Ottawa
Posts: 11,873
|
I wrote you a little function that uses regular expression and string replacement (requires ActionScript 3) to get rid of some standard rtf codes and replace the ones for bold and italics with the html equivalents.
It's not a perfect solution, and you may have to add more replacements to suit your needs, but it should get you started... Code:
var rtf:String = "";
rtf += "{\\rtf1\\ansi\\ansicpg1252\\deff0{\\fonttbl{\\f0\\fnil\\fcharset0 Arial;}{\\f1\\fnil\\fcharset0 Arial;}}\n";
rtf += "{\\colortbl ;\\red0\\green128\\blue0;\\red0\\green0\\blue0;}\n";
rtf += "\\viewkind4\\uc1\\pard\\cf1\\lang1033\\i\\f0\\fs36 (ACTC3RSL1:Q13) \\cf2\\i0\\fs48 Claude\\rquote s attitude toward Jerry is one of\\cf0\\f1\\fs41\\par\n";
rtf += "}\n";
var html:String = Rtf2Html(rtf)
trace(html);
function Rtf2Html(rtf:String):String
{
var html:String = rtf;
html = html.replace(/[\n\r\f]/g, "");
html = html.replace(/{\\rtf1[^\s]+\s.*;}}/, "");
html = html.replace(/{\\.\\generator.*;}/, "");
html = html.replace(/\\viewkind.\\uc.\\par./, "");
html = html.replace(/{\\colortbl\s.*;}/g, "");
html = html.replace(/}$/g, "");
html = html.replace(/\\{/g, "{");
html = html.replace(/\\}/g, "}");
html = html.replace(/\\tab/g, "  ");
html = html.replace(/\\par/g, ""); // might want to replace this with a "<br>" tag
html = html.replace(/\\b0[\s]*/g, "</b>");
html = html.replace(/\\b/g, "<b>");
html = html.replace(/\\i0[\s]*/g, "</i>");
html = html.replace(/\\i/g, "<i>");
html = html.replace(/\\rquote\s/g, "'");
html = html.replace(/\\lang[0-9]*/g, "");
html = html.replace(/\\cf[0-9]*/g, "");
html = html.replace(/\\fs[0-9]*/g, "");
html = html.replace(/\\f[0-9]*/g, "");
return html;
}
Quote:
|
|
|
|
|
|
|
#8 |
|
Registered User
Join Date: Mar 2010
Posts: 6
|
Thank you so much, I will give it a try.
|
|
|
|