Using symbol from library in htmlText

后端 未结 3 457
攒了一身酷
攒了一身酷 2020-12-22 08:39

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 

        
相关标签:
3条回答
  • 2020-12-22 09:08

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

    0 讨论(0)
  • 2020-12-22 09:10

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

    0 讨论(0)
  • 2020-12-22 09:15
    //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);
    
    0 讨论(0)
提交回复
热议问题