XML Image Gallery with Star Style
| Category | : Flash | Views | : 69834 | ||
| Version | : 8 | Rating | : | ||
| Type | : Text | Source File | : xml-image-gallery-with-star-style.zip | ||
| Result | : See the result | ||||
Now go to the main timeline and paste this code to load the XML:
//Import libraries for the BitmapData and Matrix objects
import flash.display.BitmapData;
import flash.geom.Matrix
//Load XML file
var image_xml = new XML()
image_xml.ignoreWhite = true;
image_xml.load("images.xml")
//Array for the path of the images
var images_path = new Array();
//Variable to keep the number of pictures in the stage
var frames = 0
image_xml.onLoad = function()
{
//Loop the nodes
for(i = 0; i < image_xml.firstChild.firstChild.childNodes.length; i++)
{
//Get the path
_root.images_path[i] = image_xml.firstChild.firstChild.childNodes[i].attributes.title;
//Create a MC
_root.createEmptyMovieClip("frames" + i, _root.getNextHighestDepth());
//Load the image using the MovieClipLoader that we will Code below
_root.MCloader.loadClip(_root.images_path[i], _root["frames" + i]);
}
}
The code below will load each image and create a copy of each frame MC.
//MovieClipLoader object to load our images
MCloader = new MovieClipLoader();
//New object to create an Event Handler
listener = new Object();
//Add the Event Handler bellow to the MovieClipLoader
MCloader.addListener(listener);
//Array to store every frame MC we create
var frames_array = new Array();
//This event is called when the image finished loading
listener.onLoadInit = function(target)
{
//Create a BitmapData object to save the loaded image.
var bmd:BitmapData = new BitmapData(200,150);
//Get the scale of the loaded image so that it
//will fit the size for our frame
var xscale = 200/target._width
var yscale = 150/target._height
//Create a Matrix object to modify the loaded image
var MT = new Matrix();
//Set the Matrix object to scale the image using
//the value we got above
MT.scale(xscale, yscale)
//Draw the "target" to the BitmapData using the
//Matrix to scale it.
bmd.draw(target, MT);
//For loop 3 times to make 3 copies of each image
for(i = 0; i < 3; i++)
{
//Attach the "frame" MC to the framesMC, which we
//will create, and use the variable "mc" to call it
mc = _root.framesMC.attachMovie("frame", "frame" + _root.frames, _root. framesMC.getNextHighestDepth());
//Create a new MC inside the frame to attach the image
mc.createEmptyMovieClip("pic", 10);
//Set the position of this MC
mc.pic._x = -100
mc.pic._y = -75
//Attach the BitmapData to it.
mc.pic.attachBitmap(bmd, 1);
//These are not the actual position of the MC. They are
//two variable inside the MC and will be explained later
mc.x = Math.random() * 2000 – 1000
mc.y = Math.random() * 1600 – 800
//Variable to tell us how far away this MC is
mc.z = _root.frames * 1000
//Set the event "onPress" to call the function
//"selectFrame" that we are going to create
mc.onPress = _root.selectFrame
//Create a function called "Move" inside every
//MC that will call another function, "moveFrames"
mc.Move = _root.moveFrames
//Set an element of the array to be a reference to this MC
_root.frames_array[_root.frames] = mc
//Increase the variable frames
_root.frames++
}
//Remove the "target" MC that loaded the image as we don't need it now
target.removeMovieClip();
}
![]() |
![]() |
![]() |
![]() |
![]() |







