Photoshop Tutorials, Flash Tutorials, 3Ds Studio Max Tutorials, Web Design Tutorials


Software Tutorials

Featured Free Templates
View All Templates!
Preview  |  Download
Name: metamorph_flame
Downloads:
Preview  |  Download
Name: metamorph_skyandclouds
Downloads:
View All Templates!
Recommended Hosting:
Host Unlimited Domains on 1 Account
1500GB storage and 15000GB bandwidth for $6.95/mo!
Recommended Hosting:
Host Unlimited Domains on 1 Account
1500GB storage and 15000GB bandwidth for $6.95/mo!
:: Free Website Templates
Preview  |  Download Preview  |  Download Preview  |  Download
Name: metamorph_sunset Name: metamorph_flower Name: metamorph_waterfall
Downloads: Downloads: Downloads:

Do You Like Our Website? Share With Others!
GoogleGoogle slashdotYahooMyWebDiggTechnoratiDelicious
Page: 12345678910111213141516171819202122232425

Welcome To WebDesignTutorials.net Flash Tutorials Area - Creating a Magnifying Glass

The aim of the tutorial is to learn how to create a magnifying glass using a very simple piece of code. You will also learn how to attach several Movie clips to the mouse, some move with the mouse and others move in the opposite direction to the mouse. You will also learn how to use masks in Flash MX.

Example of a very smooth running magnifying glass (Large file may take a moment to load).

Step one: Creating the image you want to magnify

Before you can start you will need something to magnify. This could be a bitmap image such as a Jpeg or Gif. It could also be a vector based image created with the typing or drawing tools in Flash (or in a Graphics program like Freehand, Illustrator, or CorelDraw). The vector based images are best because the file sizes are so small. Having said that they take more time to create as you have to draw every detail.

I have taken the easy root and scanned a map using PhotoShop and then saved it as a Jpeg. Quick and easy but the files size is big: nearly 200kb.

If I was concerned with the file size I could of imported the scanned picture into a Graphics program and re-created the file before I started to create my magnifying glass in Flash. I would expect the graphics file to be about 10 or 20kb (once imported to Flash) rather than 200kb. A major difference.

Of course you can do this with a map but if you are using the magnifying glass on a photo, you have to stick to the Jpeg.

The measurements of the image has to be quite large. Mine is 1200 pixels wide x 1000 pixels high. This is much taller and wider than most pictures that would be used on a web page (hence the 200KB). The reason for this is so that when magnified there is plenty of detail to look at.

Or: Create your own image. For the tutorial I recommend that you stick to the same size: 1200 x 1000 pixels

Step two: Setting up the Flash file

  1. Open a new Flash file.
  2. Go to: Modify > Document
    Set the document size to: 480 x 400 pixels
  3. Go to: File > Import
    Browse to the Jpeg/Gif file that you wish to use.
    Your Jpeg should now be on stage. If it is not on Stage it will be in your Library - Drag it onto stage.

    Note: If you are using an image from a graphics program you can copy and paste it into Flash.

  4. The magnification on my example above is 2 1/2 times or 250%. So the picture that I need on stage needs to be 250% smaller.

    1200 / 2.5 = 480 px - new width
    1000 / 2.5 = 400 px - new height

    In the Property inspector resize the image to: 480 x 400 pixels.

    Important Note: This is the same as the document size (see point 2 above).

  5. In the Property inspector place the image at: X = 0, Y = 0

    Your Property inspector should have these details.

  6. Rename the layer: Small Map

    The map is now ready to be magnified.

Step three: Preparing the Magnifying Glass

  1. Create a new Layer and call it: Big Map
  2. Go to: Insert > New Symbol
    Name: My Big Map
    Behavior: Movie Clip
  3. Drag the Jpeg of the map into the new symbol.
  4. As before place the image at: X = 0, Y = 0
    This time you do not reduce the size of the image. This is what we are going to see in the Property Inspector:

    Note the the image is still 1200 x 1000 px.

  5. Go back to the main stage and drag the new movie clip from the library and place it on the main stage.

    This movie clip must be in the new layer: Big map

    Note:
    The large map does not need to be on top of the smaller map but can be shunted off to the side of the stage. This makes it easier to work with.

  6. In the Property inspector give this movie clip an instance name: myMap

  7. Attach the following ActionScript to the new movie clip:

       onClipEvent (enterFrame) {
          _root.myMap._x = (_root._xmouse * -1.5);
          _root.myMap._y = (_root._ymouse * -1.5);
       }

    This little bit of code is the key:

    Line 1: onClipEvent (enterFrame) {
    Do this every time the play head hits the frame. Normally 12 times per second.

    Line 2: _root.myMap._x = (_root._xmouse * -1.5);
    The x position of the map moves in the opposite direction to the mouse times 1.5

    Line 3: _root.myMap._y = (_root._ymouse * -1.5);
    Same as line 2 but for the Y axis.

    Remember that the large picture is bigger than the visible stage by 2.5 times. So it will stick to the mouse position but also move more that the mouse by 1.5 times. This at first seems curious but let me explain:

    If your mouse is on x position zero so is the picture (0 x -1.5 = 0).

    Both mouse and map on _x zero.

    If your mouse is on _x position 480 (on the far right of the movie) the mouse has moved 480 pixels to the right.

    The picture moves 720 pixels to the left (480 x -1.5 = -720).

    The total mouse + picture move 1200 pixels (480 + 720 = 1200)

    This is why we get a magnification of 2.5 times (480 x 2.5 = 1200).

    Think of it like this: The mouse moves 1 part, the picture moves 1.5 parts, total 1 +1.5 = 2.5 parts/magnification.

    This illustrates the _x (sideways) movement only.

    Note: Whatever the magnification you multiply by one number less, because the cursor always moves once across the screen.

    If I wanted a magnification of 3 times the code would look like this:

       _root.myMap._x = (_root._xmouse * -2);
       _root.myMap._y = (_root._ymouse * -2);

    Note: If the magnification was 3 times, the large map would also have to be bigger or the small map (and the Flash document) smaller.

Step four: The Glass

Now we will hide the big map, except for the glass area.

  1. Create a new layer above the Big map layer called: Glass
  2. Draw a circle in this layer with a diameter of about: 145 pixels
  3. With your Arrow tool select the outside stroke of the circle.

    Stroke selected

  4. Go to: Edit > Cut

    Note:
    You will paste the stroke later to create the glass rim.

  5. Right click (Mac Ctrl Click) on the inside of the circle and convert it to a Symbol.
    Name: Circle
    Behavior: Movie Clip

    Note:
    The advantage of creating the movie clip this way is that the circle will be exactly centered in the movie clip and we need this.

    Instance of circle on stage with a centered registration point.

  6. Give the circle a Instance name: myCircle
  7. Add the following code to the circle:

       onClipEvent (enterFrame) {
          _root.myCircle._x = (_root._xmouse);
          _root.myCircle._y = (_root._ymouse);
       }

    The ActionScript is almost identical but this time the circle will stick to the cursor and move with the mouse. There is no: *-1.5

  8. Right click on the Layer name: Circle
    Select: Mask

    Your layers should look like this.

    Note: The layer stacking order is critical.

    It is probable a good time to save and test your movie, as all the main parts of the magnifying glass are done.

Step five: The Glass Rim

  1. Create a new Layer above your Circle Layer called: Glass Rim



    Note:
    It is important that the glass rim is in its own layer, otherwise the mask may fail to work correctly or the rim may not be visible.

  2. If you cut the outside stroke from the circle above (step 4.3) it should still be in the computer memory.
    Go to: Edit > Paste

    If you do not have the outside of the circle in the memory you will need to draw one. Remember to delete the centre or you will not see the magnifying glass underneath!

  3. Right click on the rim and convert it to a Symbol.
    Name: Rim
    Behavior: Movie Clip
  4. Give the circle a Instance name: myRim
  5. Attach the following code onto the movie clip:

       onClipEvent (enterFrame) {
          _root.myRim._x = (_root._xmouse);
          _root.myRim._y = (_root._ymouse);
       }

    Note: You cannot use the following code:

       onClipEvent (enterFrame) {
          startDrag("");
       }

    With startDrag you can only attach one object to the mouse and as we need to attach the rim and the mask startDrag will not work.

Step five: The Mouse Cursor - Removed

Your magnifying glass should be ready to roll. Having said that there is just one addition that you may want:

To make the standard arrow cursor disappear so that you can see the magnification detail better, place this code in any of the key frames in the time line:

Mouse.hide();
Author: Phil

Advertisements
Graphic Software, Flash Templates, Free Stock Photos, Web Templates, Web Design, Corporate Web Design, Royalty Free stock Photo, Affordable Website Design, Submit site, Add Url, Stock Photos, Survey Software, Anti Virus Software, E mail software, Computer Software

Premium Partners
  Free Website Templates - Flash templates, Affordable Website Design, Website Templates, Website Redesign, Custom Website Design, Web Design Tutorials, Flash Tutorials, Promotion Tutorials - that is what we do. Metamorphosis Design Studio offers quality, free and low cost web site templates for your business and personal life, we also offer affordable web design and site re-design.
  Vertex Website Tempales - It saves tones of time and money to use pre-made web designs to build your web site. You need a web site but you don't want to pay thousands dollars to professional web design companies? Our web templates is just for you! They are designed to be easilly edited by your favorite html editor, like MS FrontPage
  Photoshop Tutorials - Learn how to build stunning web pages using Adobe Photoshop, Macromedia Flash MX and 3D Studio Max software. The step-by-step approach makes it so easy, that even beginners can produce great web pages. Get started with these tutorials covering everything from page layout to content tips.
Free website templates and paid web templates are great tools to make your websites look perfect! You will save time and money with our flash templates and free website templates Our visitors are satisfied with the quality of our free and paid website templates! Please visit our free website templates and paid website templates sections. We offer free web templates, free web layouts, free web page templates and other stuff for free download. All templates come with the html and external css file so you may easily edit HTML with your favorite HTML editor. Feel free to download our free web templates for your personal websites.

Terms of use depend upon the website template vendor.
Home  |  Submit Tutorial  |  Top Sites  |  Free Templates  |  Website Templates  |  Privacy Policy  |  Contact Us
All Right Reserved by WebDesignTutorials.net