Failed to access embedded images in htmlText

Images can be included in controls TextAreausing the property htmlText:

ta.htmlText = '<img src="http://..."/>';

How can I reference inline images ?

Example:

<mx:TextArea xmlns:mx="http://www.adobe.com/2006/mxml">
    <mx:Script>
        <![CDATA[
            [Embed(source='../assets/img.gif')]
            public var img:Class;
        ]]>
    </mx:Script>
    <mx:htmlText>
        <![CDATA[
            <img src="???" />
        ]]>
    </mx:htmlText>
</mx:TextArea>

UPD:

<img src='../assets/img.gif />

works on the local computer, but in the server environment it throws:

Error # 2044: Unhandled IOErrorEvent :. text = Error # 2035: URL Not Found.

How can i fix this?

+3
source share
9 answers

Try:

<mx:htmlText>
        <![CDATA[
           <p>
            <img src='../assets/butterfly.gif' 
                 width='30' height='30' 
                 align='left' 
                 hspace='10' vspace='10'>
            </p>
        ]]>
     </mx:htmlText>

See the documentation .

+2
source

OK, I just spent a couple of hours sorting this out, but it works for me in Flash and Flex.

Display images in TextField

DisplayObjects TextField <img />, MovieClips, Sprites .

  • Flash Flex, , -, DisplayObject (, Sprite MovieClip).

  • , , . , , TextField .


Flash

: .

  • TextField . , txtImageTest.

  • txtImageTest , . 300x150px.

  • MovieClip , . imageClip1.

  • - imageClip1.

  • , ActionScript .

  • :

    imageClip1.wordWrap = true;
    imageClip1.multiline = true;
    imageClip1.htmlText = "<p>You can include an image in your HTML text with the &lt;img&gt; tag.</p><p><img id='testImage' src='imageClip1' align='left' width='30' height='30' hspace='10' vspace='10'/>Here is text that follows the image. I'm extending the text by lengthening this sentence until it long enough to show wrapping around the bottom of the image.</p>"
    
  • .


Flex

MovieClip , Flash, , ( Flash, ).

, BlackArrow.as:

// Set the correct package for you class here.
package embed
{
    import flash.display.Sprite;
    import mx.core.BitmapAsset;

    public class BlackArrow extends Sprite
    {
        // Embed the image you want to display here.
        [Embed(source='assets/embed/triangleIcon_black.png')]
        [Bindable]
        private var TriangleImage:Class;

        public function BlackArrow()
        {
            super();

            // Instantiate the embedded image and add it to your display list.
            var image:BitmapAsset = new TriangleImage();
            addChild(image);
        }

    }
}

.. ( Flash) BitmapAsset ( Flex), TextField. Sprite - .

, TextField:

<?xml version="1.0" encoding="utf-8"?>
<mx:VBox xmlns:mx="http://www.adobe.com/2006/mxml"
    width="100%" height="100%">

    <mx:Script>
    <![CDATA[
        import embed.BlackArrow;

        // You must include a variable declaration of the same type as your
        // wrapper class, otherwise the class won't be compiled into
        // the SWF and you will get an IOError.
        private var img2:BlackArrow;
    ]]>
    </mx:Script>

    <mx:Text id="txtResults1" width="100%" height="100%">
        <mx:htmlText>
        <![CDATA[<p>You can include an image in your HTML text with the &lt;img&gt; tag.</p><p><img id='testImage' src='embed.BlackArrow' align='left' hspace='10' vspace='10'/>Here is text that follows the image. I'm extending the text by lengthening this sentence until it long enough to show wrapping around the bottom of the image.</p>]]>
        </mx:htmlText>
    </mx:Text>

 </mx:VBox>

, src .


+9

src HTML img- htmlText, , getFullyQualifiedClassName). :

public class Example
{
    [Embed(source="myImage.png")
    public static const MyImage:Class;

    public function getHTMLImg() : String
    {
        return "<img src='" + getQualifiedClassName(MyImage) + "' />";
    }
}

, - , ...

+3

. , URL-. , . , URL- , swf, . , , , , , , - , .

, htmlText? ( , htmlText TooltipManager). : http://groups.google.com/group/flex_india/browse_thread/thread/cf0aa62afaae3fdc/b21f462f8d5da117?pli=1. , , . , .

+1

Try

src='../assets/img.gif'

: htmlText

0

src= 'assets/img.gif', , SWF-, img.gif. html, SWF .

, .

0

localhost, , . , , .SWF. ( ) .

0

! MovieClips ! TextArea ( TextArea - , OOP extenstion TextField).

, TextArea , Textfield, SWF, , - .

. www.doitflash.com, , :)

0

Sly_cardinal wrote a very helpful answer. Thanks a lot to him! I could not solve this problem for half a day. Sly_cardinal noticed that if you do so, then the getQualifiedClassName (embed bitmap) image is not inserted into the text correctly, only in the upper left corner. Sly_cardinal suggested creating a wrapper class.

I want to add my answer

New wrapper of ImageWrapper.as class →

package 
{
import flash.display.Bitmap;
import flash.display.Sprite;
public class ImageWrapper extends Sprite{
    public static var img:Class;
    public function ImageWrapper() {
        var bitmap:Bitmap = new img();
        addChild(bitmap);
    }
}
}

Call in code:

[Embed(source = "img/MyImg.png")] var _MyImg:Class;
ImageWrapper.img = _MyImg;
tf.htmlText = "My text, and my image <img src='ImageWrapper'>";

What is it. Thanks!

0
source

Source: https://habr.com/ru/post/1707003/


All Articles