06/11/2010, 15:18
|
| | Fecha de Ingreso: octubre-2010 Ubicación: San juan Argentina
Mensajes: 95
Antigüedad: 14 años, 1 mes Puntos: 0 | |
Respuesta: Ayuda para un carrusel en Flash (AS3) con XML Nose si qeres crear un Menu carrusel o un carrusel de imagenes igual te dejo que es para menu o lo que quieras le tendras qe cambiar un par de configuraciones dependiendo de lo que quieras uno y solo le cambias la ruta de el XML qe tengas creado
Código:
const IMAGE_WIDTH:uint = 70;
const IMAGE_HEIGHT:uint = 70;
var focalLength:Number = 500;
var vanishingPointX:Number = stage.stageWidth / 2;
var vanishingPointY:Number = stage.stageHeight / 2;
var floor:Number = 40;
var angleSpeed:Number = 0;
var radius:Number = 200;
var xmlFilePath:String = "iconos.xml";
var xml:XML;
var imageHolders:Array = new Array();
var numberOfLoadedImages:uint = 0;
var numberOfImages:uint = 0;
var loader = new URLLoader();
loader.load(new URLRequest(xmlFilePath));
loader.addEventListener(Event.COMPLETE, xmlLoaded);
function xmlLoaded(e:Event):void {
xml = new XML(loader.data);
xml.ignoreWhitespace = true;
loadImages();
}
function loadImages():void {
numberOfImages = xml.number_of_images;
for each (var image:XML in xml.images.image) {
var imageHolder:MovieClip = new MovieClip();
var imageLoader = new Loader();
imageHolder.addChild(imageLoader);
imageHolder.mouseChildren = false;
imageLoader.x = - (IMAGE_WIDTH / 2);
imageLoader.y = - (IMAGE_HEIGHT / 2);
imageHolder.urlxml = image.url;
imageHolders.push(imageHolder);
imageLoader.load(new URLRequest(image.url));
imageLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, imageLoaded);
}
}
function imageLoaded(e:Event):void {
numberOfLoadedImages++;
e.target.content.smoothing = true;
if (numberOfLoadedImages == numberOfImages) {
//Set up the carousel
initializeCarousel();
}
}
function initializeCarousel():void {
var angleDifference:Number = Math.PI * (360 / numberOfImages) / 180;
for (var i:uint = 0; i < imageHolders.length; i++) {
var imageHolder:MovieClip = (MovieClip)(imageHolders[i]);
var startingAngle:Number = angleDifference * i;
imageHolder.xpos3D = radius * Math.cos(startingAngle);
imageHolder.zpos3D = radius * Math.sin(startingAngle);
imageHolder.ypos3D = floor;
imageHolder.currentAngle = startingAngle;
var scaleRatio = focalLength/(focalLength + imageHolder.zpos3D);
imageHolder.scaleX = imageHolder.scaleY = scaleRatio;
imageHolder.alpha = 0.3;
imageHolder.addEventListener(MouseEvent.MOUSE_OVER, mouseOverImage);
imageHolder.addEventListener(MouseEvent.MOUSE_OUT, mouseOutImage);
imageHolder.addEventListener(MouseEvent.CLICK, imageClicked);
imageHolder.x = vanishingPointX + imageHolder.xpos3D * scaleRatio;
imageHolder.y = vanishingPointY + imageHolder.ypos3D * scaleRatio;
addChild(imageHolder);
}
addEventListener(Event.ENTER_FRAME, rotateCarousel);
}
function rotateCarousel(e:Event):void {
angleSpeed = (mouseX / stage.stageWidth * 0.1);
for (var i:uint = 0; i < imageHolders.length; i++) {
var imageHolder:MovieClip = (MovieClip)(imageHolders[i]);
imageHolder.currentAngle += angleSpeed;
imageHolder.xpos3D=radius*Math.cos(imageHolder.currentAngle);
imageHolder.zpos3D=radius*Math.sin(imageHolder.currentAngle);
var scaleRatio = focalLength/(focalLength + imageHolder.zpos3D);
imageHolder.scaleX=imageHolder.scaleY=scaleRatio;
imageHolder.x=vanishingPointX+imageHolder.xpos3D*scaleRatio;
imageHolder.y=vanishingPointY+imageHolder.ypos3D*scaleRatio;
}
//sortZ();
}
function sortZ():void {
imageHolders.sortOn("zpos3D", Array.NUMERIC | Array.DESCENDING);
//Set new child indexes for the images
for (var i:uint = 0; i < imageHolders.length; i++)
setChildIndex(imageHolders[i], i);
}
//This function is called when the mouse is over an imageHolder
function mouseOverImage(e:Event):void {
//Set alpha to 1
e.target.alpha=1;
}
function mouseOutImage(e:Event):void {
//Set alpha to 0.3
e.target.alpha=0.3;
}
function imageClicked(e:Event):void {
navigateToURL(new URLRequest(e.target.urlxml));
}
SALUDOS |