Using symbol from library in htmlText <img> tag in ActionScript 3

点点圈 提交于 2019-11-29 18:03:41

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);
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!