Internet Cross Logo
Internet Cross your one stop web tutorial website

Loading JPG Images

by Diego Park
There are situations where we would be interested in loading images depending on certain actions. Macromedia Flash allows loading JPG images, as they would be native SWF movie clips. One application of the function loadMovie() can be when developing galleries of pictures.


Loading JPG Images

To load JPG images to movie clips, we need to invoke the method loadMovie(). We use the name of the target instead of the level for convenience. When loading images, please remember to align the marquee to left and top –first and fourth button- using the window Align. If you forget to do this, the image would be displayed misaligned.

We included a handler for the movie clip cover in a separate layer (Layer 1). Its code is:

cover.onLoad=function()
{
loadMovie("example.jpg","cover");
}


This loads the image called example.jpg into the instance cover when this movie clip is loaded. For debugging purposes, we added a trivial code that displaces the image as the mouse moves.

This portion of code is:

onClipEvent (enterFrame)
{
_x=_root._xmouse-(_width>>1);
_y=_root._ymouse-(_height>>1);
}


Please note that shifting one bit to right the value of _width is equivalent to dividing it by two. And we need the parenthesis because of precedence of operators in ActionScript.

Conclusion

With a very simple function, we loaded a JPG image into a movie clip. Using this function enables us to create more complex galleries of images.

[Page 1]
Visit our forums to discuss / post your problems.