O'Reilly logo

Actionscript Cookbook by Joey Lott

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

15.4. Loading an External Image (All Formats)

Problem

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

Solution

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

Discussion

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/ ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required