November 26th, 2008Playing with flash bitmapdata
Playing with the bitmapdata in flash 9 (I shoud be trying falsh 10 soon!).
Below is the source code
package {
import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.display.Sprite;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.filters.BlurFilter;
import flash.filters.ColorMatrixFilter;
import flash.geom.Point;
public class SoundFun extends Sprite
{
[Embed(source="../assets/gfx/star.png")]
private var ImageIcon:Class
private var _destX:int = 0;
private var _destY:int = 0;
private var bp:Bitmap;
private var xSpeed:int = 0;
private var ySpeed:int = 0;
private var bpd:BitmapData;
private var image:Bitmap;
private var bpf:BlurFilter
private var bpc:ColorMatrixFilter;
public function SoundFun()
{
image = new ImageIcon();
image.scaleX = image.scaleY = 0.3;
//this.height = 540;
//this.width = 600;
bpf = new BlurFilter(6,6,1);
bpc = new ColorMatrixFilter([1,0,0,0,0,
0,4,0,0,0,
0,0,1,0,0,
0,0,0,1,0]);
addEventListener(Event.ADDED_TO_STAGE,onAddedToStage);
}
private function onEnterFrame(evt:Event):void
{
xSpeed = (_destX - bp.x) * 0.3;
ySpeed = (_destY - bp.y) * 0.3;
image.rotation += Math.sin(45) * 10;
//image.y += Math.cos(ySpeed) * 0.3;
bpd.applyFilter(bpd,bpd.rect,new Point(0,0),bpf);
bpd.applyFilter(bpd,bpd.rect,new Point(0,0),bpc);
bpd.draw(stage);
}
private function onMouseClick(evt:MouseEvent):void
{
_destX = evt.localX;
_destY = evt.localY;
trace(”mouse Click”);
}
private function onAddedToStage(evt:Event):void
{
addChild(image);
image.y = 200;
image.x = 150;
bpd = new BitmapData(400,400);
bp = new Bitmap(bpd);
addChild(bp);
stage.addEventListener(MouseEvent.CLICK,onMouseClick);
addEventListener(Event.ENTER_FRAME,onEnterFrame);
}
}
}
