Problem is this: I need to add image to textField using img tag, but I cannot reference a symbol from a library in my swf file.
txt.htmlText = "test <img src='symbol1' height='10' width='10' align='right'/>";
AS linkage for this symbol is symbol1 and i tried embedding this swf in my class but it always gives error #2035 - URL not found
Adobe says that img tag accepts a library symbol, but I couldn't find any example where this is true.
Any help would be appreciated.
It's a while since I did this but I think you need to create a movie clip in the library with the bitmap inside it, then export that for ActionScript, then add that as the linkage in the tag.
So, if your movieClip is exported as 'myImage_mc", your html will be:
<img src="myImage_mc" width="100" height ="100"/>
Update.
To clarify, here's my symbol in the library:
Here's my actionscript:
import flash.text.TextField;
var textField:TextField = new TextField();
textField.htmlText = "<p>HKP</p><img src='HKP'/>";
textField.x = textField.y = 100;
stage.addChild(textField);
And here's the result (which admittedly needs a bit of tweaking):
Note: this doesn't seem to work if the img is the only tag in the field. You have to add some text, even if it is not visible. An empty P won't work, so either of these will fail:
textField.htmlText = "<img src='HKP'/>";
textField.htmlText = "<p></p><img src='HKP'/>";
... but this works:
textField.htmlText = "<p> </p><img src='HKP'/>";
... which is pretty much a classic Adobe gotcha ;)
for your source try adding the image extension, such as image.jpg or image.png
textfield.htmlText = "<img src='image_name.jpg' width='100' height='100'/>
";
//Displays img on stage. No text is necessary
var txt:TextField = new TextField ();
txt.wordWrap = true;//this is necessary or img won't display
txt.width = 400;//size up to avoid cutting off image
txt.height = 200;//this doesn't affect the image size or proportion
txt.htmlText = '<img src="yourimage.png" />';
addChild(txt);
来源:https://stackoverflow.com/questions/12068933/using-symbol-from-library-in-htmltext-img-tag-in-actionscript-3