My First BitmapData Experiment

Wow this is a crazy class! Just bought the Actionscript dictionary for Flash 8 and thought I’d give the BitmapData class a whirl. I’m actually starting to understand it now. The wacky example below uses copyPixel() to break apart a PNG and move it around all squishy.

[as]import flash.display.BitmapData;
import flash.geom.Rectangle;
import flash.geom.Point;

var r:Number = 24;
var c:Number = 24;

var photoB:BitmapData = new BitmapData(photo._width,photo._height);
photoB.draw(photo);

for(i=0;i for(j=0;j var t:MovieClip = this.createEmptyMovieClip(“c”+this.getNextHighestDepth(),this.getNextHighestDepth());
t._y = i*5 + 50;
t._x = j*5 + 50;
var tb:BitmapData = new BitmapData(5,5);
t.attachBitmap(tb,1);
tb.copyPixels(photoB,new Rectangle(j*5,i*5,5,5),new Point(0,0));
t.j = j+1;
t.i = i+1;
t.onEnterFrame = moveIt;
}
}

function moveIt() {
this._x += (((_root._xmouse + (this.j*5))-60) – this._x) / (this.j*this.i)*this.j;
this._y += (((_root._ymouse + (this.i*5))-60) – this._y) / (this.i*this.j)*this.i;
}
[/as]


Commentary

  1. James hay says:

    Nice one… i’ve only recently begun to work with it and i’m well impressed (try it with as3.0 cos you get a massive performance increase and can do tonnes with it ;)

    James

  2. nice example! I myself just delve into the Flash 8 Bitmap stuff. Do you got a link to where one can oder the Flash 8 Actionscript Dictionary you mentioned?

  3. Smith says:

    Cool effect , try to add a blur effect , this ll act as an antialiasing :p

  4. Phil says:

    Great effect…….

  5. Saeed Ashour says:

    So wired , i did n’t see any script how you did load the picture :(

    Nice Example

  6. Peter says:

    cool example, don’t you just love how you can now do these type of effects in under 30 lines of code — absolutely incredibly *w00t*

  7. Lee Brimelow says:

    Saeed,

    I have the photo in a MovieClip off stage with an instance name of “photo”. I could have loaded it dynamically though since Flash 8 supports loading external PNGs.

  8. MooDy says:

    gr8 Werk Lee , U did it again m8 .

    Well , Its Amazing how you are sharing Information and Capturing tuts to Educate the World , And you Deserve all the best .

    Im currently Building my own Site [General Personal info ] , Its taking more time than i thought ..
    But as soon as i get that 1 done , i will Send ya a link .
    hope you dont mind having your link on my site =\

    moo .

  9. Edward says:

    Hey Lee could you ponit me to the tool you use for incerting formated actionscript into you wordpress blog?

    It would be quite a handy tool!

  10. joran says:

    cool trick…however it really slows down with bigger images…maybe with AS3 its better..

  11. Sarah says:

    Wired , I can’t see any script how you did load the picture? I can’t figure it out

  12. adriaan says:

    Take a look at MovieClipLoader class or MovieClip.loadMovie().

Leave a Comment