Good evening :yoshi:,
I am having an issue using getCharBoundaries() with htmlText. In the following code, I am trying to get the location of <img> tags, so that I can then move the image to where the <img> tag in the text, rather than the image being placed on the next line. getCharBoundaries returns an actual rectangle when I use plain text, but when it’s htmlText, the function returns null (I put in a trace statement just to make sure of whether I was getting null or not). I’ve read that getCharBoundaries() can be unpredictable; does anyone know of a workaround or why this might be happening? Thanks!
Even if I try calling getCharBoundaries on a character a few positions before the img tag, so that it’s an actual character and not markup, I still get a null value returned.
import fl.text.TextField;
var myText:String = "";
myText += "<p>You can use the <b> tag to create <b>bold</b> text.</p>";
myText += "<p>You can use the <i> tag to create <i>italic</i> text.</p>";
myText += "<p>You can use the <u> tag to create <u>underlined</a> text.</p>";
myText += "<p>You can use the <a> tag to create <a href='[http://www.adobe.com](http://www.adobe.com/)'>links to other sites</a>.</p>";
myText += "<p>You can use the <br> tag to create<br>new lines of text<br>whenever you want.</p>";
myText += "<p>You can use the <font> tag to specificy different font <font color='#FF0000'>colors</font>, <font size='16'>sizes</font>, or <font face='Times New Roman'>faces</font>.</p>";
myText += "<p>You can use the <img> tag to load images or SWF files:<br><img src='http://www.helpexamples.com/flash/images/logo.png' id = 'myPic'>.</p>";
var tf:TextField = new TextField();
tf.multiline = true;
tf.wordWrap = true;
tf.htmlText = myText;
addChild(tf);
tf.height = tf.textHeight + 1000;
tf.width = tf.textWidth + 1000;
var index:int = 0;
var indx = 0; //x value of char boundary rectangle
var indy = 0; ////x value of char boundary rectangle
var iconLocs:Array = [];
while (true)
{
// Find every placeholder tag and mark their location
index = myText.indexOf("<img ", index);
if (index > 0)
{
iconLocs.push(index);
trace(tf.getCharBoundaries(index));
index += 5;
}
else
{
break;
}
}