In this tutorial we’ll see how easy it is to load jpg images into Flash dynamically.
Please note that Flash can load only non-progressive jpg images.
To load our images, we’ll use the loadMovie
method. This method can be called from any movie clip object, including the root.
It takes two parameters: URL
, and the optional variables
parameter. The URL
parameter provides a valid Web address for any JPEG image, while the optional variables
parameter uses the HTTP
method (GET
or POST
) to send variables to the URL.
Download the sample files here.
1. Start a new movie — mine had dimensions of 350×350 pixels.
2. Open the components panel by hitting ctrl+f7.
3. Drag 3 instances of the PushButton
component on the stage, and select the first PushButton
component in Frame 1.
4. The component’s parameters are displayed in the Property inspector.
5. Type "hen" into the Property inspector Instance Name text box.
6. Type "call_Img" for the Click Handler name.
7. Type "Show Hen" for the Label name. Similarly, for other buttons, type:
————————————————-
ButtonName, LabelName, ClickHandlerName
————————————————-
(a). hen , Show Hen , call_Img
(b). cheetah , Show Cheetah , call_Img
(c). hen , Show Hen , call_Img
————————————————-
8. Select Frame1. Press F9 (Windows) to open the actions box.
9. Insert the action:
filejpg = function(picName)
{
//set the position of picHolder movie clip to center of stage
picHolder._x = 80
picHolder._y = 10
//Load the pictures
picHolder.loadMovie(picName);
}
function call_Img(name)
{
//Give correct path here
if(name == hen){filejpg("hen.jpg");}
if(name == cheetah){filejpg("cheetah.jpg");}
if(name == tiger){filejpg("tiger.jpg");}
}
//create a empty movie clip for holding the Jpg pics
createEmptyMovieClip("picHolder", 1);
That’s all it takes! Before you test the movie, ensure that the pictures are in the same folder as the movie.
Georgina has more than fifteen years' experience writing and editing for web, print and voice. With a background in marketing and a passion for words, the time Georgina spent with companies like Sausage Software and sitepoint.com cemented her lasting interest in the media, persuasion, and communications culture.