ecco tutto il codice
codice:
// Setta l'x e y iniziali delle immagini
_global.thisX = 4.5;
_global.thisY = 10;
var gallery_xml:XML = new XML();
gallery_xml.ignoreWhite = true;
gallery_xml.onLoad = function(success:Boolean) {
try {
if (success) {
var images:Array = this.firstChild.childNodes;
var gallery_array:Array = new Array();
for (var i = 0; i<images.length; i++) {
gallery_array.push({src:images[i].firstChild.nodeValue});
}
//x titoli
var title_array:Array = new Array();
for (var i = 0; i<images.length; i++) {
title_array.push({src:images[i].attributes.tit});
}
//x commenti
var comment_array:Array = new Array();
for (var i = 0; i<images.length; i++) {
comment_array.push({src:images[i].attributes.desc});
}
displayGallery(gallery_array);
} else {
throw new Error("Unable to parse XML");
}
} catch (e_err:Error) {
trace(e_err.message);
} finally {
delete this;
}
};
gallery_xml.load("screenshot/gallery.xml");
/* funizone che crea un loop x ongi immagine nell'array e crea movie clip sullo */
function displayGallery(gallery_array:Array) {
var galleryLength:Number = gallery_array.length;
for (var i = 0; i<galleryLength; i++) {
var thisMC:MovieClip = this.createEmptyMovieClip("image_"+i, i);
// carica l'img
mcLoader_mcl.loadClip("screenshot/"+gallery_array[i].src, thisMC);
// inserisci il preloader
preloaderMC = this.attachMovie("preloader_mc", "preloader"+i+"_mc", 5000+i);
preloaderMC.bar_mc._xscale = 0;
preloaderMC.progress_txt.text = "0%";
thisMC._x = _global.thisX;
thisMC._y = _global.thisY;
preloaderMC._x = _global.thisX;
preloaderMC._y = _global.thisY+20;
// se ci sono + di 4 img inizia nuova riga
if ((i+1)%4 == 0) {
// reset the X and Y positions
_global.thisX = 4.5;
_global.thisY += 110;
} else {
_global.thisX += 160;
}
}
}
var mcLoader_mcl:MovieClipLoader = new MovieClipLoader();
var mclListener:Object = new Object();
mclListener.onLoadStart = function() {
};
mclListener.onLoadProgress = function(target_mc, loadedBytes, totalBytes) {
var pctLoaded:Number = Math.round(loadedBytes/totalBytes*100);
var preloaderMC = target_mc._parent["preloader"+target_mc.getDepth()+"_mc"];
preloaderMC.bar_mc._xscale = pctLoaded;
preloaderMC.progress_txt.text = pctLoaded+"%";
};
mclListener.onLoadInit = function(evt:MovieClip) {
evt._parent["preloader"+evt.getDepth()+"_mc"].removeMovieClip();
var thisWidth:Number = evt._width;
var thisHeight:Number = evt._height;
var borderWidth:Number = 0;
var marginWidth:Number = 2;
evt.scale = 75;
//disegno rettangolo bianco con bordo nero intorno all'img
evt.lineStyle(borderWidth, 0x000000, 100);
evt.beginFill(0xFFFFFF, 100);
evt.moveTo(-borderWidth-marginWidth, -borderWidth-marginWidth);
evt.lineTo(thisWidth+borderWidth+marginWidth, -borderWidth-marginWidth);
evt.lineTo(thisWidth+borderWidth+marginWidth, thisHeight+borderWidth+marginWidth);
evt.lineTo(-borderWidth-marginWidth, thisHeight+borderWidth+marginWidth);
evt.lineTo(-borderWidth-marginWidth, -borderWidth-marginWidth);
evt.endFill();
//scalo l'img e la ruoto
evt._xscale = evt.scale;
evt._yscale = evt.scale;
evt._rotation = Math.round(Math.random()*-6)+3;
//controllo quando l'img viene premuta
evt.onRelease = function() {
if (k==1){
k++;
//prendo il numero dell'immagine dal nome x risalire al titolo e descrizione
var str:String = evt._name;
var numero:String = str.substring(6);
var n1:Number = new Number(numero);
Qui vorrei avere l'array con i titoli e uno con la descrizione in modo
che riprendo i dati usando come indice n1
this.origX = this._x;
this.origY = this._y;
this.origr = this._rotation;
this.orig_gall = _parent.gall._y;
this._xscale = 185;
this._yscale = 185;
this._x = 0;
this._y = 0;
this._rotation = 0;
_parent.muovi = 0;
_parent.gall._y = 0;
this.swapDepths(this._parent.getNextHighestDepth());
_parent.rect._alpha=100;
}else{
k--;
this._xscale = this.scale;
this._yscale = this.scale;
this._x = this.origX;
this._y = this.origY;
this._rotation = this.origr;
_parent.gall._y = this.orig_gall;
_parent.muovi = 1;
_parent.rect._alpha=0;
}
};
};
mcLoader_mcl.addListener(mclListener);
Grazie ancora
Marco