Loading Images (AS2)

images

1 AS2 differs significantly in how it loads images. In fact, there’s more than one way to do it. The approach that comes closest to the ease of AS3 involves the MovieClipLoader class. In this case, you’ll want an empty movie clip. Again we’ll call it holder, as before, to act as the container for your image which lets you position the JPG as desired. Loading the image isn’t especially complicated, but responding when the load is complete … that’s a little more convoluted. Here’s the easy part, first.

images

2 In this case, photo is an instance of the MovieClipLoader class. The name is a bit misleading, because this class also loads JPGs, GIFs and PNGs, depending on what version of the Flash Player you publish to (see the Help docs for specifics). The MovieClipLoader.loadClip() method is invoked on the photo instance, specifying the file to load and the movie clip to load it into.

images

3 To recognize when the image has loaded, we’ll need to program an event listener using an instance of the Object class. This generic object will act as a liaison between the MovieClipLoader instance and its event handler function. In this case, the association is not as direct as it is in the AS3 examples. The name of the listener variable isn’t important, but it’s listening for events, so “listener” makes sense enough. This variable points to an object, and the object is given an onLoadInit property, which is set to a function (the event handler). Why onLoadInit? The MovieClipLoader class provides quite a few events, listed in the ActionScript 2.0 Language Reference, and this is the one that not only states when content is loaded, but allows access to the properties and methods of the loaded content. The function references the holder movie clip and sets its _xscale and _yscale properties to 45%. Finally, the MovieClipLoader instance, photo, is associated with the listener object. Note, in AS2, under these circumstances, that method is addListener(), not addEventListener().

images

4 Now that you know about event handling, dragging and dropping, pausing timelines and loading images, try testing yourself by developing a cool little Flash application that incorporates buttons that, when clicked, load external images to create a fun photo gallery. Then try extending this functionality to allow each image to be dragged and dropped around the Flash stage.

 

image

Hot Tip

Properties like alpha and scale belong to different camps, between AS3 and AS2. In ActionScript 3.0, these sorts of property generally range between 0 and 1, which makes 22% look like 0.22. In ActionScript 2.0, these usually range between 0 and 100.

images

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.116.43.124