New Component: Lens Effect
A while back we demonstrated how to make a magnifying glass using simple masking. Although this masking technique works very well, it cannot be used to simulate fish-eye type lenses or other lenses that result in distortion of the image.
Using the Flash 8 displacement filter, we have created a new component that simplifies the creation of lenses that show distortion.
The lens outline can be made invisible which allows the user to distort areas of an image in a seamless manner. The image below is an example of such distortions. The left most image is the unaltered image, the middle image shows its head expanded using a magnify lens and the right most image shows its head reduced using a reducing lens.
This component will work with SWiSH Max3 and miniMax3 with build dates of 20091130 or later, and although the component is not included with the 20091130 build’s installer, it can be download here.
After downloading it, extract both files within the zip file to:
C:\Program Files\SWiSH Max3\Components\Effects\2D\
Note that the exact location may be different depending on where you installed Max3. The component will also be included with future versions of Max3 and miniMax3 within the Effects\2D\ component group.
Other lens effects are possible and they are demonstrated in the flash file below. Note that for most of the demonstrated effects, you can drag the lens with the mouse. Press the next button to cycle through some of the possible variations.
To use the Lens component, drag it onto the stage and expand it in the Outline panel. Insert the items that you which to place “under” the lens into the container movie clip. As you place items into the container movie clip, note that the component will align them so that the top left most item is aligned with the container clip top left hand corner. This alignment is necessary for the component to work correctly. Once you have added your items, the testmovie movie clip can be deleted.
The default position of the lens can be adjusted by dragging the lensoutline object. The color of the lens outline can be altered using the properties panel for the lens outline. Do not alter any other properties such as name, width, height, _x or _y scale. Altering any of those properties will prevent the component from working correctly.
| Parameter | Description |
| Strength | Strength of the effect. Generally a value of 100 works well. Increase value for larger lenses or fisheye lenses (6,7,8). A – value makes a reducing lens. |
| Diameter | Diameter of the lens. Use this to adjust the size of the lens. Note that the component if scaled, will not work correctly. This is a limitation of flash 8 filters. |
| LensType | 1: Linear Magnify 2: Linear Reduce 3: Non linear magnification 4: x^3 5: x^4 6: fisheye1 (magnify / reduce) 7: fisheye2 (magnify / reduce) 8: fisheye3 (reduce) – use strength of around 300 9: 5disk fresnel |
| Mask | Hide everything outside of lens. If set to true only the area inside the lens is shown. |
| Dragable | If set to true, the lens can be dragged. |
| Hide Lens Outline | If set to true, hide the lens outline. Dragging is disabled if lens outline is hidden using this parameter. If you wish to have a draggable lens without any visible outline, then alter the colors of lensoutline as described above, setting each gradient band to 0% alpha. |
| Advanced | |
| BitmapSize | Using a higher value will give a better effect, but will take longer to initially load. Doubling this value will cause the bitmap creation to take 4 times longer. 300 is a good compromise between quality and speed. Note that this value is only used if the chosen diameter is larger than this value. |
| Reduce By | Reduce the lens area by this many pixels to ensure that it fits into the lensoutline. Use this if the lens appears to extend beyond the lens outline. |
| Reduce Mask By | Reduce the mask area by this many pixels. Use this to mask out lens abberations when used in masking mode. |
The component also has the following methods:
SetLensPosition(xpos:Number,ypos:Number) – move the lens to the selected x,y position within the component. the position is with respect to top right hand corner.
SetStrength(s:Number) – change the strength of the lens. This is the same as altering the Strength parameter. – values tend to reduce the size, + values tend to magnify. Typically values should be < 150, although for fisheye lens types higher values work well.
Notes:
Due to a limitation of flash 8 filters, the component will not work correctly if scaled or placed inside of a movie clip that is scaled.
If scaling is applied, the lens area as defined by the parameter Diameter will not be altered, however the overlaying lens outline (and mask) will be scaled and moved according to the scaling that is applied.
You can however scale the objects within the container movie clip to make the source object larger or smaller.
Source .swi for the example movie demonstrated above, can be downloaded from here.
I hope you enjoy using this new component.
Tags: displacement filter, effect, filter, lens



Wow! great stuff, thanks a lot!
Cool, thanks for sharing with us :)
This is a great tool! Thanks for your generosity!
Fantastic article. I’ve favorited this website so I can follow your follow-ups. Thanks for taking the energy to share this.
This post looks very good. I’m happy that I have found it!
where is more info about this?
This information looks really good. It is good that I have found it!