
Alright, in this example, I am cutting each pixel in an image and piecing it back together again. Only this time I animating the pixel to a new location, piecing back the image at 200%. I think this can open a lot doors in what you can do with a bitmap.
Here is the Bitmap test 2 example
Here is the code
Actionscript:
-
import flash.display.*;
-
import caurina.transitions.Tweener;
-
//holds all the pixels
-
var pixHolder:Sprite = new Sprite();
-
//linkage to img in library
-
var img:Img = new Img();
-
-
addChild(pixHolder);
-
-
//array that will hold info of each pixel
-
var pixels_array:Array = [];
-
//bitmapdata of the img
-
var bmd:BitmapData = new BitmapData(img.width, img.height, false);
-
//put the img bitmapdata in the new bitmapdata object
-
bmd.draw(img, new Matrix());
-
//I heard this helps performance
-
bmd.lock();
-
//loop thru each pixel
-
//i.e. i= 0; j = 0 then i=1; j = 0 then i = 2; j = 0 you get it right?
-
for (var i:int = 0; i <img.width; i++)
-
{
-
for (var j:int = 0; j <img.height; j++)
-
{
-
//create an obj to hold each pixels info
-
var coords:Object = {};
-
-
//in this example I decided to use a rect graphic instead of a single bitmap
-
//for fun
-
var pixSprite:Sprite = new Sprite();
-
//make a pixSprite for each pixel
-
pixSprite.graphics.beginFill(bmd.getPixel(i, j), 1);
-
-
pixSprite.graphics.drawRect(0, 0, 1, 1);
-
pixSprite.graphics.endFill();
-
// add an event listener to each pixel to animate
-
pixSprite.addEventListener(MouseEvent.MOUSE_OVER, updating, false, 0, true);
-
//put pixels in their right place
-
pixSprite.x = i;
-
pixSprite.y = j;
-
pixHolder.addChild(pixSprite);
-
}
-
}
-
-
bmd.unlock();
-
//you don't need the data in memory any more
-
bmd.dispose();
-
-
function updating(evt:MouseEvent):void
-
{
-
//the moused over pixel removes listener, scales 200% and moves down to make a img at 200%
-
evt.currentTarget.removeEventListener(MouseEvent.MOUSE_OVER, updating);
-
trace("over");
-
Tweener.addTween(evt.currentTarget, {scaleX:2, scaleY:2, x: img.width + evt.currentTarget.x * 2, y: img.height + evt.currentTarget.y * 2, transition:"linear", time:.5});
-
}
Last 5 posts in actionscript
- Using Flash Player 10 to produce Dynamic Musical Notes - May 20th, 2008
- Flash Player 10 Dynamic Sound Generation - May 20th, 2008
- How to compile and examples for Flash Player 10 or ASTRO BETA - May 16th, 2008
- How to use Bitmap and BitmapData in ActionScript 3 - v1 - April 21st, 2008
- How to add and remove Mediators in a actionscript-3 puremvc app - March 30th, 2008
Last 5 posts in as3
- Using Flash Player 10 to produce Dynamic Musical Notes - May 20th, 2008
- Flash Player 10 Dynamic Sound Generation - May 20th, 2008
- How to load Pixel Bender in Flash Player 10 - May 19th, 2008
- How to compile and examples for Flash Player 10 or ASTRO BETA - May 16th, 2008
- How to use Bitmap and BitmapData in ActionScript 3 - v3 - April 29th, 2008
Last 5 posts in Bitmap/BitmapData
- Flash Player 10 Dynamic Sound Generation - May 20th, 2008
- How to use Bitmap and BitmapData in ActionScript 3 - v3 - April 29th, 2008
- How to use Bitmap and BitmapData in ActionScript 3 - v1 - April 21st, 2008
Last 5 posts in flash
- Using Flash Player 10 to produce Dynamic Musical Notes - May 20th, 2008
- Flash Player 10 Dynamic Sound Generation - May 20th, 2008
- How to load Pixel Bender in Flash Player 10 - May 19th, 2008
- How to compile and examples for Flash Player 10 or ASTRO BETA - May 16th, 2008
- How to use Bitmap and BitmapData in ActionScript 3 - v3 - April 29th, 2008
Last 5 posts in flash CS3
- How to use the FileSystem in AIR to find the users directory folders - March 1st, 2008
- Yahoo Maps ActionScript 3.0 Released - February 11th, 2008
- Update: Flash/Flex Tidbit #2 How to use Alpha Mask in Flash CS3 - January 8th, 2008
- Custom ColorPicker Component - How to extend a Flash CS3 Component Class - December 13th, 2007
- Tidbit #3 - testing additions to your code - Control Variable - November 28th, 2007
Josh Weatherspoon, A self-proclaimed millionaire who for some reason has to work as a Flash Developer, at Travelocity in Dallas(Southlake), TX.


Sorry, no comments yet.