XML Image Gallery with Falling Pictures (Snow Effect)
| Category | : Flash | Views | : 34363 | ||
| Version | : 8 | Rating | : | ||
| Type | : Text | Source File | : xml-image-gallery-with-falling-pictures.zip | ||
| Result | : See the result | ||||
Now the images fall, but we still need them to animate when the user clicks. Paste:
//when the user click the mouse button
onClipEvent(mouseDown)
{
//if the mouse is over this MC and it's not selected already
if ((this.hitTest(_root._xmouse, _root._ymouse, true)) && (!select))
{
//Bring the MC to the top of the others
this.swapDepths(_root.getNextHighestDepth());
//This MC is now selected so set the variable to true
select = true;
//Create a new Tween object for every property we need to animate
xTw = new Tween(this, "_x", Regular.easeIn, this._x, 400, 2, true);
yTw = new Tween(this, "_y", Regular.easeIn, this._y, 250, 2, true);
xSTw = new Tween(this, "_xscale", Regular.easeIn, this._xscale, 100, 2, true);
ySTw = new Tween(this, "_yscale", Regular.easeIn, this._yscale, 100, 2, true);
alphaTw = new Tween(this, "_alpha", Regular.easeIn, this._alpha, 100, 2, true);
rotTw = new Tween(this, "_rotation", Regular.easeIn, this._rotation, 0, 1, true);
}
//If this MC is selected, but the mouse was not clicked over it
else if ((select) && (!(this.hitTest(_root._xmouse, _root._ymouse, true))))
{
//This MC is not selected
select = false;
//Call the function "yoyo()" of the Tween objects to
//make the MC go back to its original properties
xTw.yoyo();
yTw.yoyo();
xSTw.yoyo();
ySTw.yoyo();
alphaTw.yoyo();
rotTw.yoyo();
}
}
Test your code, everything should work now.
Code Explanation
import flash.display.BitmapData;
import flash.geom.Matrix
These two line import the libraries BitmapData and Matrix; the BitmapData is used to save the loaded image to be reused in the copies and the Matrix is used to scale the image to fit the frame.
var image_xml = new XML();
image_xml.ignoreWhite = true;
image_xml.load("images.xml")
Load the XML to get the paths.
var images_path = new Array();
This variable is used to store the paths from the XML.
frames = 0;
ready = false;
The first variable is used to know how many frame we have and to give unique names to the copies when the images are loaded, the second variable controls whether the MCs can fall or not.
MCloader = new MovieClipLoader();
listener = new Object();
MCloader.addListener(listener);
A MovieClipLoader allows us to load images to an MC just like the function "loadMovie()" would, but with the MCL we can know exactly when it's done loading.But we need to create the Event Handler ourselves; to do that we create a new Object, the handler (below) and we add this object as a listener to the MCL.
The function "addListener()" takes only one parameter, the object with the event handler.
![]() |
![]() |
![]() |
![]() |
![]() |







