Code Snippets   | [Bill's Home]

Reducing file sizes in Flash

Macromedia Flash is an excellent package for creating graphics, but designers must watch not to create file sizes which take a long time to download. Thus it is often better to create an application with just enough graphics to create the basic environment, and then load the graphic files when they are required. An example of this is in my diary (see below), where the graphics on the Flash and Mail tabs are actually loaded when they are required.

Rather than integrating the graphics into Flash, we can load the graphics when they are required. Initially the graphic files are converted into a SWF format, such as:

Next we can add a blank movie to the Flash and then add a button to the frame which will load the SWF files (as given below). The movie instance is given the name of MOV.

The code below shows that a variable (movie_value) is used to keep track of the current graphic to show. Every time the button is pressed the action script is called, and the new graphic is shown.

Flash code

on (release) {
movie_value++;
if (movie_value>13) {
movie_value = 1;
}


if (movie_value==1)
loadMovie ("agent01.swf", "mov");

else if (movie_value==2)
loadMovie ("reuse_movie.swf", "mov");

else if (movie_value==3)
loadMovie ("show_agents.swf", "mov");

else if (movie_value==4)
loadMovie ("pics_cookie.swf", "mov");

else if (movie_value==5)
loadMovie ("flash_mobile_agents.swf", "mov");

else if (movie_value==6)
loadMovie ("pics_cat01.swf", "mov");

else if (movie_value==7)
loadMovie ("pics_cat02.swf", "mov");

else if (movie_value==8)
loadMovie ("pics_cat03.swf", "mov");

else if (movie_value==9)
loadMovie ("pics_cat04.swf", "mov");

else if (movie_value==10)
loadMovie ("flash_to_napier.swf", "mov");

else if (movie_value==11)
loadMovie ("alien.swf", "mov");

else if (movie_value==12)
loadMovie ("cnds_at_napier.swf", "mov");

else if (movie_value==13)
loadMovie ("cisco_banner.swf", "mov");
}