Hi,
please, can you help me?
i need to reconstruct image with this. but not with MOUSE_OVER event but automatic, maybe Timer…
And need to do it random…
I ,ve got a headache from this…
Help anyone?
Martin
//Import TweenLite
import com.greensock.*;
import com.greensock.easing.*;
import flash.utils.*
var tiles:Array = new Array();
//Image piece's width and height
const IMAGE_PIECE_WIDTH:uint=35;
const IMAGE_PIECE_HEIGHT:uint=17;
//We want to know how many image pieces there are on the stage
var imagePieces:Number=0;
//Load an image and listen when the loading is complete
var imageLoader:Loader = new Loader();
imageLoader.load(new URLRequest("o2-pf2010-mms-front-update.jpg"));
imageLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, completeHandler);
//This function is called when the image is loaded.
//We slice the image into pieces and add the image pieces to the stage.
//An image piece will be invisible before the user hovers over the piece.
function completeHandler(event:Event):void {
//Get the bitmap data of the loaded image
var imageTextureMap:BitmapData=event.target.content.bitmapData;
//Calculate how many colums and rows we will have
var columns:Number=Math.ceil(imageTextureMap.width/IMAGE_PIECE_WIDTH);
var rows:Number=Math.ceil(imageTextureMap.height/IMAGE_PIECE_HEIGHT);
//Loop through the colums
for (var i = 0; i < columns; i++) {
//Loop through the rows
for (var j = 0; j < rows; j++) {
//Create a new movieclip that holds a single image piece
var imagePieceHolder:MovieClip = new MovieClip();
//We want the image holder to be invisible at the beginning
imagePieceHolder.alpha=0;
//Create a new image piece, to which we will copy bitmap data
//from the original image.
var imagePiece:Bitmap = new Bitmap();
imagePiece.bitmapData=new BitmapData(IMAGE_PIECE_WIDTH,IMAGE_PIECE_HEIGHT);
//Copy a rectangular area from the original image into our image piece.
imagePiece.bitmapData.copyPixels(imageTextureMap,
new Rectangle(i * IMAGE_PIECE_WIDTH, j * IMAGE_PIECE_HEIGHT,
IMAGE_PIECE_WIDTH, IMAGE_PIECE_HEIGHT),
new Point(0,0));
//Add the image piece to an image holder
imagePieceHolder.addChild(imagePiece);
//Set the image piece onto the holder so that the image's center
//is at the top left corner of the holder. This way the rotation
//will look natural.
imagePiece.x = -(IMAGE_PIECE_WIDTH / 2);
imagePiece.y = -(IMAGE_PIECE_HEIGHT / 2);
//Position the image holder to the stage.
//We position the holders so that it looks like one single image.
imagePieceHolder.x=i*IMAGE_PIECE_WIDTH+IMAGE_PIECE_WIDTH/2;
imagePieceHolder.y=j*IMAGE_PIECE_HEIGHT+IMAGE_PIECE_HEIGHT/2;
//Listen when the mouse hovers over an image piece holder
imagePieceHolder.addEventListener(MouseEvent.MOUSE_OVER, mouseOverHandler);
//Update the image pieces counter
imagePieces++;
//Add the imagePiece holder to the stage
addChild(imagePieceHolder);
tiles.push(imagePieceHolder);
}
}
trace(tiles.lenght);
}
//This function is called when the user hovers over an image piece holder
function mouseOverHandler(e:MouseEvent):void {
trace(tiles.length);
//Save the holder to a local variable
var imagePieceHolder = (MovieClip)(e.target);
//Add the holder to the top of the display list.
//This way the boxes will overlap each others correctly.
setChildIndex(imagePieceHolder,imagePieces - 1);
//Set the alpha to one so the holder is visible
imagePieceHolder.alpha=1;
//Tween the holder (rotate, scale & alpha)
TweenLite.from(imagePieceHolder, 1, {rotation: 0, scaleX: 3, scaleY: 3, alpha: 0});
//We don't want to receive any more mouse events for this holder
//imagePieceHolder.mouseEnabled = false;
//Remove the MOUSE_OVER event listener
imagePieceHolder.removeEventListener(MouseEvent.MOUSE_OVER, mouseOverHandler);
}