when the embedFonts is removed, it works perfectly as expect. Otherwise when an image is clicked, it selects the whole text around it.
Alternatively can anyone suggest a method to style dynamic textfields instead of using html?
I was able to have bring the same effect without using the anchor tag. Apparently there's a bug in using Anchor tag with images. Anyway here's what I did to overcome this.
import flash.display.*;
import flash.text.*;
import flash.events.*;
import flash.ui.Mouse;
private function init():void {
//....
var txt:String = "Curabitur dolor eros, gravida et.<p class='defStyle'><img src='003.jpg' id='0002'><br><br><br><br><br>Quisque facilisis erat a dui. Nam malesuada ornare dolor. Cras gravida, diam sit amet rhoncus ornare, erat elit consectetuer erat, id egestas pede nibh eget odio.</p>";
testtext.htmlText=txt;
var myPattern:RegExp =/<img[^>]+ids*=s*['"]([A-Za-z0-9]+)['"][^>]*\s*>/igmxs;
var result:Object = myPattern.exec(txt);
while (result != null) {
var id = result[1];
trace(id);
var image:DisplayObject = testtext.getImageReference(id);
image.addEventListener(MouseEvent.CLICK, imgClick);
image.addEventListener(MouseEvent.MOUSE_OVER, mouseOverHandler);
image.addEventListener(MouseEvent.MOUSE_OUT, mouseOutHandler);
result = myPattern.exec(txt);
}
...//more
}
function imgClick(e:MouseEvent):void {
trace('hello '+e.target.name);
}
function mouseOverHandler(e:MouseEvent):void {
Mouse.cursor='button';
}
function mouseOutHandler(e:MouseEvent):void {
Mouse.cursor='auto';
}