Macromedia Flash Professional 8 Unleashed

In previous versions of Flash, the only visuals that could be loaded in at runtime were nonprogressive JPEGs and SWF files. Now you can import GIFs, PNGs, and progressive JPEGs in the same manner as in previous versions of Flash. When you import any of these image types with transparency, the transparency will be maintained.

Following is an example of loading a progressive JPEG as a background image and then loading a PNG image over top of it.

You can use any images you like, or grab the ones from the website.

1.

Create a new Flash document.

2.

In the first frame, open the Actions panel (Window, Actions) and place this code in it:

//create the two movieclips to hold the images var image1:MovieClip = this.createEmptyMovieClip("image1_mc",1); var image2:MovieClip = this.createEmptyMovieClip("image2_mc",2); //now load the first image image1.loadMovie("mountains.jpg"); //then, when the user clicks the stage, the second image will load this.onMouseDown = function(){ image2.loadMovie("atSign.png"); }

The preceding code first creates two empty movie clips to house the images you are loading. Then you load the background image into the first movie clip. After that, you create an event so that when a user clicks the mouse on the stage, the second image will load.

Test this movie, and you should see something like Figure 1.13. Notice that the transparency of the second image is maintained.

Figure 1.13. Flash can load in transparent PNGs at runtime.

Категории