SandeR2
May 12th, 2009, 10:23 AM
Hi,
Currently I'm working on a system to let customers write a small comment.
I'm using a xml file to load the comments, but somehow something goes wrong when I try to give it some special formatting.
Here is my as3 code:
package classes{
import flash.display.Sprite;
import flash.display.Graphics;
import flash.xml.*;
import flash.events.*;
import flash.net.*;
import flash.text.TextField;
import flash.text.TextFormat;
public class Comments extends Sprite {
private var xmlLoader:URLLoader;
private var xmlData:XML;
private var commentChildren:XMLList;
private var speak:Speaker;
private var txt:TextField;
private var tFmt:TextFormat;
public function Comments() {
tFmt = new TextFormat;
tFmt.color = 0xF0F0F0;
tFmt.font = "Complete in him";
tFmt.size = 14;
xmlLoader = new URLLoader();
xmlData = new XML();
xmlLoader.addEventListener(Event.COMPLETE, loadXML);
xmlLoader.load(new URLRequest("comments.xml"));
function loadXML(e:Event):void {
xmlData = new XML(e.target.data);
parseComments(xmlData);
}
function parseComments(commentsInput:XML):void {
commentChildren = commentsInput.comment.child("message");
for (var i:int = 0; i < commentChildren.length(); i++) {
graphics.beginFill(0x3d3d3d);
graphics.drawRoundRect(20,20+77*i,200,75,10,10);
graphics.endFill();
txt = new TextField();
txt.x = 25;
txt.y = 25+77*i;
txt.height = 65;
txt.width = 190;
txt.defaultTextFormat = tFmt;
txt.htmlText = commentChildren[i];
txt.wordWrap = true;
txt.embedFonts = true;
txt.antiAliasType = "ADVANCED";
txt.selectable = false;
txt.background = true;
txt.backgroundColor = 0xFF0000;
addChild(txt);
}
for (i = 0; i < commentChildren.length()-1; i++) {
speak = new Speaker();
speak.x = 180;
speak.y = 95+77*i;
addChild(speak);
}
}
}
}
}My XML code:
<comments>
<comment>
<message>Musters Koeriers # Lorem ipsum dolor sit amet, consectetur adipiscing elit. In eget dui purus. Lorem ipsum dolor sitar.</message>
</comment>
<comment>
<message><font color="#ccff00">Gipel Tilburg</font>Lorem ipsum dolor sit amet, consectetur adipiscing elit. In eget dui purus. Lorem ipsum dolor sitar.</message>
</comment>
<comment>
<message><font color="#ccff00">Bink Interieurs</font>Lorem ipsum dolor sit amet, consectetur adipiscing elit. In eget dui purus. Lorem ipsum dolor sitar.</message>
</comment>
</comments>
Now as you can see in the xml the 1st message is without any formatting, the 2nd and 3rd are. In the attached comment.jpg you can see what the result is. I can't figure out where the "enter" and those extra "spaces" are coming from but I suspect it's from the 'font' tags.
btw. those red background are just the textField backgrounds to show where the text should start.
Did anyone else come across this problem, and how can it be fixed.
Thanks in advance.
_Sander2
Currently I'm working on a system to let customers write a small comment.
I'm using a xml file to load the comments, but somehow something goes wrong when I try to give it some special formatting.
Here is my as3 code:
package classes{
import flash.display.Sprite;
import flash.display.Graphics;
import flash.xml.*;
import flash.events.*;
import flash.net.*;
import flash.text.TextField;
import flash.text.TextFormat;
public class Comments extends Sprite {
private var xmlLoader:URLLoader;
private var xmlData:XML;
private var commentChildren:XMLList;
private var speak:Speaker;
private var txt:TextField;
private var tFmt:TextFormat;
public function Comments() {
tFmt = new TextFormat;
tFmt.color = 0xF0F0F0;
tFmt.font = "Complete in him";
tFmt.size = 14;
xmlLoader = new URLLoader();
xmlData = new XML();
xmlLoader.addEventListener(Event.COMPLETE, loadXML);
xmlLoader.load(new URLRequest("comments.xml"));
function loadXML(e:Event):void {
xmlData = new XML(e.target.data);
parseComments(xmlData);
}
function parseComments(commentsInput:XML):void {
commentChildren = commentsInput.comment.child("message");
for (var i:int = 0; i < commentChildren.length(); i++) {
graphics.beginFill(0x3d3d3d);
graphics.drawRoundRect(20,20+77*i,200,75,10,10);
graphics.endFill();
txt = new TextField();
txt.x = 25;
txt.y = 25+77*i;
txt.height = 65;
txt.width = 190;
txt.defaultTextFormat = tFmt;
txt.htmlText = commentChildren[i];
txt.wordWrap = true;
txt.embedFonts = true;
txt.antiAliasType = "ADVANCED";
txt.selectable = false;
txt.background = true;
txt.backgroundColor = 0xFF0000;
addChild(txt);
}
for (i = 0; i < commentChildren.length()-1; i++) {
speak = new Speaker();
speak.x = 180;
speak.y = 95+77*i;
addChild(speak);
}
}
}
}
}My XML code:
<comments>
<comment>
<message>Musters Koeriers # Lorem ipsum dolor sit amet, consectetur adipiscing elit. In eget dui purus. Lorem ipsum dolor sitar.</message>
</comment>
<comment>
<message><font color="#ccff00">Gipel Tilburg</font>Lorem ipsum dolor sit amet, consectetur adipiscing elit. In eget dui purus. Lorem ipsum dolor sitar.</message>
</comment>
<comment>
<message><font color="#ccff00">Bink Interieurs</font>Lorem ipsum dolor sit amet, consectetur adipiscing elit. In eget dui purus. Lorem ipsum dolor sitar.</message>
</comment>
</comments>
Now as you can see in the xml the 1st message is without any formatting, the 2nd and 3rd are. In the attached comment.jpg you can see what the result is. I can't figure out where the "enter" and those extra "spaces" are coming from but I suspect it's from the 'font' tags.
btw. those red background are just the textField backgrounds to show where the text should start.
Did anyone else come across this problem, and how can it be fixed.
Thanks in advance.
_Sander2