Here’s my question. I’m trying to create a rippling effect for use in a touch-sensitive kiosk – when the user touches the screen, I want it to create a ripple effect (a sort of replacement for the mouse cursor).
I’ve created a gradientBox on a matrix, blah blah blah, and it appears as though the animation function I’ve thrown together works – almost. I’m not sure how to erase the “old” gradientBoxes before the new one gets drawn.
Here’s the code I’m using: Just copy it and save it and set it as the document class for a new movie to test.
I would greatly appreciate any help or direction! Thanks!
package
{
import flash.display.MovieClip;
import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.display.BitmapDataChannel;
import flash.display.GradientType;
import flash.filters.DisplacementMapFilter;
import flash.filters.DisplacementMapFilterMode;
import flash.geom.Matrix;
import flash.geom.Point;
import flash.events.*;
import flash.ui.Mouse;
public class DMFilterExample extends MovieClip
{
internal static var gbX:Number;
internal static var gbY:Number;
internal static var gbR:Number;
internal static var gbD:uint;
internal static var myMatrix:Matrix;
internal static var myBitmapData:BitmapData;
public function DMFilterExample ()
{
/**
* Base all of the circle's values on these numbers: including the
* gradientBox! The relationships here will kill the world if messed up!
*/
gbX=200;
gbY=200;
gbR=75;
gbD=0;
buildRippler(gbR*0.5);
this.stage.addEventListener(Event.ENTER_FRAME, animateRippler);
}
private function buildRippler (tmpGbR:Number):void
{
if (!tmpGbR) tmpGbR=gbR;
myMatrix=new Matrix();
myMatrix.createGradientBox(tmpGbR*2, tmpGbR*2, 0, gbX-tmpGbR, gbY-tmpGbR);
var colors:Array=[0xFF0000, 0xFF0000, 0xFF0000];
var alphas:Array=[0, 0.3, 0];
var ratios:Array=[0, 207, 255];
this.graphics.lineStyle(1, 0x000000, 0.3, false); // Debugging.
this.graphics.beginGradientFill(GradientType.RADIAL, colors, alphas, ratios, myMatrix);
this.graphics.drawCircle(gbX, gbY, tmpGbR);
if (myBitmapData) myBitmapData.dispose();
myBitmapData=new BitmapData(tmpGbR*2, tmpGbR*2, true, 0x000000)
myBitmapData.draw(this, myMatrix);
}
public function animateRippler (e:Event):void
{
gbD++;
gbD%=360;
buildRippler(Math.abs(((Math.PI/180)*Math.sin(gbD)*(gbR*0.75))*(gbR)));
}
}
}
FYI, once I get things working, this rippler won’t be the document class…I’m just trying to take one step at a time…thanks!