Embedding SWF and image files

To embed an image or SWF file in a text field, specify the absolute or relative path to the image (GIF, JPEG, or PNG) or SWF file in the <img> tag's src attribute. For example, the following example inserts a GIF file that's located in the same directory as the SWF file (a relative address, on or offline).

Embedding an image in a text field:

  1. Create a new Flash document, and save it as embedding.fla.
  2. Add the following ActionScript to Frame 1 of the main Timeline:
    this.createTextField("image1_txt", 10, 50, 50, 450, 150);
    image1_txt.html = true;
    image1_txt.htmlText = "<p>Here's a picture from my vacation:<img src='beach.gif'>";
    

    The preceding code creates a new dynamic text field on the Stage, enables HTML formatting, and adds some text and a local image to the text field.

  3. Add the following ActionScript below the code added in the previous step:
    this.createTextField("image2_txt", 20, 50, 200, 400, 150);
    image2_txt.html = true;
    image2_txt.htmlText = "<p>Here's a picture from my garden:<img src='http://www.helpexamples.com/flash/images/image2.jpg'>";
    

    You can also insert an image by using an absolute address. The preceding code inserts a JPEG file that's located in a directory that's on a server. The SWF file that contains this code might be on your hard disk or on a server.

  4. Save the document and select Control > Test Movie to test the document.

    The upper text field should have a sentence of text and most likely an error message in the Output panel saying that Flash was unable to locate a file named beach.gif in the current directory. The lower text field should have a sentence of text and an image of a flower that was loaded from the remote server.

    Copy a GIF image to the same directory as the FLA and rename the image to beach.gif and select Control > Test Movie to retest the Flash document.

NOTE

When using absolute URLs, you must make sure that your URL is prefixed with http://.