I am making a 3d portfolio site for my friend who is a photographer and graphic designer. I am very much enjoying developing it. I am using Papervision 3D for this project. So lets come to the objective of this post. There is a About me section and my friend wants the feature where she could edit the “about me” details through some dynamic editor like built in php. So basically i am giving my friend a basic editor features also with support of basic html tags to define the structure like “p b i br” etc. And there will be an xml file where all this content along with html tags will be written to. I’l be parsing this xml file from my as3 code and display it. Yeah there is a separate css file also for formatting the content but its not dynamic. So this is the objective and really i had problem with rendering content according to associated html tags.

Problem: I am rendering contents to TextField using its htmlText property and its styleSheet property for css. Every sentence starts with extra three or four spaces. With every ‘br’ tag comes extra 2 new lines. So basically i was having problem dealing with these extra space and extra new lines.

First i googled it and found many solution for removing extra spaces and new lines but nothing worked or maybe they weren’t working for htmlText or i don’t know the reason so i came up with my own solution by writing a code to eliminate extra spaces and extra new lines. Though my this code wasn’t fool proof but it worked to some extent as it removed extra spaces and new lines. But still it wasn’t 100 % perfect regarding alignment. Here was my code that i wrote to dissolve this problem:

var original:Array=contents.split("\n");
contents=original.join("");
var original1:Array = this.contents.split(" ");
var tempStr:String = "";
for (var i:int = 0; i < original1.length; i++) {
   if (original1[i]=="") {
       continue;
   }
   original1[i] += " ";
   tempStr += original1[i] ;
}
contents = tempStr;

So what i am doing is splitting every word following new line into array indexes and joining to empty string. And in case of spaces i am doing same but i am restoring the spaces back that was there between words that is only eliminating first and last extra spaces.

This was working okie, i would say 95 % but not full perfect as few lines when rendered to TextBox had some very minor alignment issues so i had to come up with some other good solution.

But accidently i found the solution which i couldn’t find in google heheheh 😛 (maybe i didn’t searched properly). I use FlashDevelop for my coding, yeah its an awesome IDE. So i typed ” .”(period operator) after my textfield reference variable and list of methods and properties appeared. I was going through all and found this life saving property called “condenseWhite”. condenseWhite removes all extra spaces and new lines from html text if property is set to true. So simple solution and i was scratching my head and writing all those code to resolve this problem.

So bottom line if u are parsing html text in as3 and if you get extra spaces and new lines when rendered to TextField the just set the condenseWhite property to true. I hope it helps someone who face same problem like me.

Gracias.