15.4. Loading an External Image (All Formats)


You want to load image formats such as BMP, GIF, PNG, or progressive JPEG files into your Flash movie.


Because MovieClip.loadMovie( ) supports only nonprogressive JPEG files, convert the image into the proper JPEG format before calling loadMovie( ).


The Flash Player supports runtime loading of only nonprogressive JPEG images. If you want to load images of another format, you have two basic options:

  • Convert the image to JPEG format and save it to the server during authoring time.

  • Use a server-side script to convert the image from the original format to a JPEG on the fly.

This recipe provides several different scripts depending on the server platform you are using. ColdFusion, Perl, .NET, and PHP scripts are included.

The ColdFusion version of the script is Java-based, so it requires ColdFusion MX. Additionally, this script requires that the <cfcontent> tag is enabled on the server. Some server administrators disable this tag for security reasons. You can download the necessary files, already compiled, from http://www.person13.com/ascb/.

Alternatively, if you want to write the code yourself, follow these steps:

  1. To compile the Java classes, you need the Java 2 Standard Development Kit (J2SDK), available from http://java.sun.com/j2se/downloads.html.

  2. Download and install the Java Advanced Imaging (JAI) API on your local computer. You need this so that you can compile the Java class. You can download the API from http://java.sun.com/products/java-media/jai/ ...

Get Actionscript Cookbook now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.