Flash Script β Dynamic JPEG Image Loader in Flash MX
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.