1 Reply Latest reply on Jan 27, 2011 3:15 PM by Ned Murphy

    Fisheye effect

    xcmuddman Level 1

      Hi All,


      I want an area in my movie to act as a fisheye/lens effect which is on at all times and to distort the movieClip that will be moving behind it.

      Currently i am trying to modify the following code so that you dont have to CLICK the mouse to see the effect take place... it should just be on from the time the movie is opened. I tried the onLoad command but must not have had the code in the correct spot.

      can anyone help?



      import com.greensock.easing.Back;
      import com.greensock.easing.Elastic;
      import com.greensock.TweenNano;
      import flash.display.BitmapData;
      import flash.display.MovieClip;
      import flash.display.Sprite;
      import flash.events.Event;
      import flash.events.MouseEvent;
      import flash.filters.DisplacementMapFilter;
      import flash.filters.DisplacementMapFilterMode;
      import flash.geom.Point;

        * ...
        * @author Zach
      public class Main extends MovieClip
        public var displacementSource:Sprite // the symbol that we use to create our displacement mapl
        private var displacementData:BitmapData
        private var displacementFilter:DisplacementMapFilter;
        public var displacementAmount:Number = 0;
        public var image:Sprite;
        public function Main():void
         if (stage) init();
         else addEventListener(Event.ADDED_TO_STAGE, init);
        private function init(e:Event = null):void
         removeEventListener(Event.ADDED_TO_STAGE, init);
         // entry point
         displacementSource.visible = false;
         displacementData = new BitmapData(displacementSource.width, displacementSource.height, true, 0x00000000);
         displacementFilter = new DisplacementMapFilter(displacementData, new Point(-100, -67),1, 2, displacementAmount, displacementAmount, DisplacementMapFilterMode.COLOR, 0, 0);
         stage.addEventListener(MouseEvent.CLICK, startDistortion);
        private function startDistortion(e:MouseEvent):void

         if(displacementAmount == 0){
          TweenNano.to(this, 1.5, { displacementAmount:200, onUpdate:applyFilters, ease:Elastic.easeOut } );
         } else {
          displacementAmount = 0;

        private function applyFilters():void
         displacementFilter.scaleX = displacementFilter.scaleY = displacementAmount;
         image.filters = [displacementFilter];


        • 1. Re: Fisheye effect
          Ned Murphy Adobe Community Professional & MVP

          That appears to be all AS3 code, so you are poosting in the wrong forum.  And if you are adding that to an AS2 design, it won't work.  For the code in question, if you change the two lines that are pulled from that code and shown as follows you might get what you want (comments included for clarification)... I can't be sure since I can't readily tell what that class is doing...


             startDistortion();  // replaces: stage.addEventListener(MouseEvent.CLICK, startDistortion);
            private function startDistortion():void    // removed argument