Skip to main content
January 27, 2011
Answered

Fisheye effect

  • January 27, 2011
  • 1 reply
  • 1502 views

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?

thanks.

package 
{
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;

/**
  * ...
  * @7111211 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);
   displacementData.draw(displacementSource);
   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;
    applyFilters();
   }

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

}

This topic has been closed for replies.
Correct answer Ned Murphy

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

1 reply

Ned Murphy
Ned MurphyCorrect answer
Legend
January 27, 2011

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