XML Image Gallery with Falling Pictures (Snow Effect) - Page 5
Posted by : webzo on Mar 08, 2008
Next
listener.onLoadInit = function(target)
{
This is the Event Handler for when the "target" is done loading. The parameter target is the object to where we are loading. var bmd:BitmapData = new BitmapData(500,375); Create a new BitmapData with the size you used inside you frame, in my case the size is "500x375".
var xscale = 500/target._width;
var yscale = 375/target._height;
The image we are loading is probably bigger than the size we want so we need to scale it and we need to know the scale.
We just divide the width and height we want by the width and height of the target (the image). The result will be used in the Matrix object so that 1 equals 100%, 0.5 equals 50%, etc. var MT = new Matrix(); The Matrix object can be used as a parameter in the draw() function of the BitmapData, we need to use it to scale the image. MT.scale(xscale, yscale); Set the Matrix to scale using the values we got previously. bmd.draw(target, MT); Draw the Bitmap with the target and the properties of the Matrix.
for(i = 0; i < 10; i++)
{
Loop ten times to make ten copies of the same image. duplicateMovieClip(frame1, "copy" + _root.frames + i, _root.getNextHighestDepth()); Duplicate the MC that is on the stage. mc = _root["copy" + _root.frames + i] Assign the new MC to the variable "mc" to call it like that now. mc.createEmptyMovieClip("pic", 10); Create a new MC called "pic" inside the duplicate we just made.
mc.pic._x = -250;
mc.pic._y = -187.5;
Set the position of the "pic" MC; this MC is where we are going to attach the Bitmap so its position needs to be where you want the picture to start. mc.pic.attachBitmap(bmd, 1); Attach the Bitmap with the picture to the "pic" MC with the depth of 1.
}
target.removeMovieClip();
Remove the image that was loaded as we won't need it anymore.
_root.frames++;
_root.ready = true;
}
Increase "frames" by one and let the MCs fall.

no comment
Add comment