Go Back   Northcode Support > SWF Studio V3
FAQ Members List Calendar Search Today's Posts Mark Forums Read

Reply
 
Thread Tools Search this Thread Display Modes
Old 2012-03-22, 09:35 PM   #1
tjh#9
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.
tjh#9 is offline   Reply With Quote
Old 2012-03-23, 02:24 AM   #2
northcode
Tim
 
northcode's Avatar
 
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.
northcode is offline   Reply With Quote
Old 2012-03-23, 09:39 AM   #3
tjh#9
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.
tjh#9 is offline   Reply With Quote
Old 2012-03-23, 10:49 AM   #4
northcode
Tim
 
northcode's Avatar
 
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.
northcode is offline   Reply With Quote
Old 2012-03-23, 11:47 AM   #5
tjh#9
Registered User
 
Join Date: Mar 2010
Posts: 6
yes, I have researching but so far I have come up empty. Any ideas?

Thank you
tjh#9 is offline   Reply With Quote
Old 2012-03-23, 07:36 PM   #6
northcode
Tim
 
northcode's Avatar
 
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?
northcode is offline   Reply With Quote
Old 2012-03-24, 04:26 PM   #7
northcode
Tim
 
northcode's Avatar
 
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, "   &nbsp");
   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;
}
The output (using your example RTF string as input) is shown below. The output is in a format that you can dump into a regular HTML text field in Flash.

Quote:
<i> (ACTC3RSL1:Q13) </i> Claude's attitude toward Jerry is one of
northcode is offline   Reply With Quote
Old 2012-03-25, 07:51 PM   #8
tjh#9
Registered User
 
Join Date: Mar 2010
Posts: 6
Thank you so much, I will give it a try.
tjh#9 is offline   Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes