Web Design Tutorials: Photoshop, HTML, Flash, PHP

Flash Tutorial – Magnifying Glass Effect

This tutorial will teach you how to create a magnifying glass effect with ActionScript 3.

1. Create a new document (size should be the same as the image’s size you’ll be using).

2. Import your image to the stage.

3. Convert the image into a movie clip called “backgroundImage”.

4. Give the movie clip an instance name of “backgroundImage”.

5. Duplicate the movie clip (backgroundImage), give the duplicate a name of “maskedImage”.

6. Create a new layer called “masked image”

7. Drag the maskedImage onto the new layer. Give it an instance name of “maskedImage”. Make sure the maskedImage is exactly on top of the backgroundImage.

8. Now hide the “masked image” layer.

Hide

9. Blur the backgroundImage to value 10.

Hide

10. You can now view the maskedImage layer again. We’ll soon move to ActionScript, but before that, let’s create the actual magnifying glass.

11. Create a new layer called “mask circle” and draw a circle of the height you want. I chose a radius of 50px.

12. Convert the circle into a movie clip “maskCircle”(registration point in the center). Give it an instance name of “maskCircle”.

13. Now let’s move over to ActionScript. Create an actions layer and type the following.

//This set's the mask to the image.
maskedImage.mask = maskCircle;

//Let's hide the mouse
Mouse.hide();

addEventListener(Event.ENTER_FRAME, enterFrameHandler);

//In each frame, we want to move the circle to the place of the mouse
function enterFrameHandler(e:Event):void {
	maskCircle.x = mouseX;
	maskCircle.y = mouseY;
}

Now test your movie. You should have a same looking effect as seen in the first page. Remember, you can do all sorts of masks, not just the magnifying effect. For example, you could make the background completely black as I’ve done in the movie below. Play with this, and create something new!

Click the movie to see what happens. To create an effect like that, type the following.

stage.addEventListener(MouseEvent.CLICK, clickHandler);

//If the user click the mouse, expand the mask so that it reveals the whole image
function clickHandler(e:Event):void {
	//Let's remove the old enterFrameHandler
	removeEventListener(Event.ENTER_FRAME, enterFrameHandler);
	//Add another ENTER_FRAME listener
	addEventListener(Event.ENTER_FRAME, scaleMask);
	//Show the mouse
	Mouse.show();
}

//In each frame, increase the scale of the circle
function scaleMask(e:Event):void {
	maskCircle.scaleX += 0.2;
	maskCircle.scaleY += 0.2;
}

Final code

//This set's the mask to the image.
maskedImage.mask = maskCircle;

//Let's hide the mouse
Mouse.hide();

addEventListener(Event.ENTER_FRAME, enterFrameHandler);

//In each frame, we want to move the circle to the place of the mouse
function enterFrameHandler(e:Event):void {
	maskCircle.x = mouseX;
	maskCircle.y = mouseY;
}

stage.addEventListener(MouseEvent.CLICK, clickHandler);

//If the user click the mouse, expand the mask so that it reveals the whole image
function clickHandler(e:Event):void {
	//Let's remove the old enterFrameHandler
	removeEventListener(Event.ENTER_FRAME, enterFrameHandler);
	//Add another ENTER_FRAME listener
	addEventListener(Event.ENTER_FRAME, scaleMask);
	//Show the mouse
	Mouse.show();
}

//In each frame, increase the scale of the circle
function scaleMask(e:Event):void {
	maskCircle.scaleX += 0.2;
	maskCircle.scaleY += 0.2;
}

Source: tutorials.flashmymind.com

you may also like:

  • Flash Tutorials – How to create an Advanced Image Gallery
    In this tutorial we will learn how to make an Flash Image Gallery using Action Script 2.0 with Smooth Transitions and Description for your images. This will be an Advanced Flash Gallery, but very easy...
  • Flash Tutorial – Create an Advanced Image Gallery
    In this tutorial we will learn how to make an Flash Image Gallery using Action Script 2.0 with Smooth Transitions and Description for your images. This will be an Advanced Flash Gallery, but very easy...
  • Flash Tutorial – Loading Multiple Images
    This tutorial will show you how to load multiple images with ActionScript 3. We will also add a simple preloader to each image. Click the “Start Loading” button to see the images appear! After this tu...
  • Flash Tutorial – Flash Spray Effect
    In this tutorial, I will show you how to create a spray effect in Flash. You can try the movie above to see how it looks. You can change the color, density and size of the spray to see how the effect ...
  • Flash Tutorial – Revealing an Image
    In this tutorial, I will teach you how to reveal an image as seen in the Flash movie. Go ahead and move your mouse over the stage to see the effect! All this is done with ActionScript 3 and a little h...

Leave a Reply

Powered by WordPress | Designed by Elegant Themes