prog.hu: Flash MovieClip Transform AS3
http://prog.hu/tudastar/138796/Flash+MovieClip+Transform+AS3.html
/**
* Copyright szbzs2004 ( http://wonderfl.net/user/szbzs2004 )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/qIZM
*/
package {
import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.display.BitmapDataChannel;
import flash.display.Loader;
import flash.display.Sprite;
import flash.events.Event;
import flash.filters.DisplacementMapFilter;
import flash.filters.DisplacementMapFilterMode;
import flash.geom.Point;
import flash.geom.Rectangle;
import flash.net.URLRequest;
import flash.system.LoaderContext;
public class ImageBend extends Sprite {
private static const AMPLITUDE:Number = 15;
private var pic:Loader;
private var originalImage:Bitmap;
public function ImageBend() {
pic = new Loader();
pic.contentLoaderInfo.addEventListener(Event.COMPLETE, loadComplete);
pic.load(new URLRequest("http://assets.wonderfl.net/images/related_images/a/ae/aec3/aec30fea75d59f0c9d5344f5aa1c220888968111"), new LoaderContext(true));
}
private function loadComplete(e:Event):void {
originalImage = new Bitmap((pic.content as Bitmap).bitmapData);
addChild(originalImage);
pic.x += pic.width + 10;
addChild(pic);
bend();
}
private function bend():void {
var dpmBmData:BitmapData = new BitmapData(pic.width, pic.height + 2 * AMPLITUDE, false);
for (var i:uint = 0; i < pic.width; ++i) {
var c:uint = 0xff * Math.sin(Math.PI * i / pic.width);
dpmBmData.fillRect(new Rectangle(i, 0, 1, dpmBmData.height), c);
}
pic.filters = [new DisplacementMapFilter(dpmBmData, new Point(0, -AMPLITUDE), BitmapDataChannel.BLUE, BitmapDataChannel.BLUE, 0, -AMPLITUDE, DisplacementMapFilterMode.COLOR, 0, 0)];
pic.y += AMPLITUDE / 2;
}
}
}