0

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.

puzdrow
  • 1
  • 1
  • 1
  • 2

3 Answers3

2

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:

Library symbol

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):

Output

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 ;)

Jude Fisher
  • 11,138
  • 7
  • 48
  • 91
  • It seems that I can't access a symbol from library. It works when I export a single symbol to swf file, and then use that swf as a source in img tag. But I need to use symbols from library and I can't access it any way. An example would be great... – puzdrow Aug 22 '12 at 09:53
  • Thank you for this example, but maybe I wasn't clear enough. I'm using FlashBuilder and i need to change htmlText in TextField in runtime, to add images into text, to replace some tag with an image. It works for me in Flash Professional too, but I'm having trouble doing this in FlashBuilder. Thanks again for your effort. – puzdrow Aug 22 '12 at 10:17
  • You didn't mention FlashBuilder. It should work just the same way if you create the symbol in FlashProfessional, export that whole FLA as a SWC, then include the SWC in your project as a library. You can google this - there are tons of references. I'm sure this is possible but don't have any more time this morning, so good luck, I hope you work it out. – Jude Fisher Aug 22 '12 at 10:21
  • 1
    @JcFx, Thanks for the additional gotcha! It drives me crazy the image just won't appear, put an extra empty space makes it all work!! – Aaron Shen Jan 25 '18 at 06:47
0

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'/>";

djrconcepts
  • 635
  • 5
  • 6
0
//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);