Qualcuno sa spiegarmi come funziona un listener? Io proprio non riesco a capire..
In pratica ho creato una galleria Flash e XML a scorrimento laterale. Prende le immagini e le mette una di fianco all'altra e le fa scorrere al passaggio del mouse. Finchè le immagini sono tutte larghe uguali (e quindi dichiaro la larghezza nell'XML) nessun problema, me le posiziona nel modo giusto. Ma avrei la necessità di inserire immagini di larghezza diversa e quindi di posizionarle di volta in volta in base alla larghezza di quelle precedenti. Carico le immagini dentro un MovieClip e dopo che sono state caricate dovrei trovare la larghezza per ricavare la _x a cui posizionarle. Mi è stato detto di usare un listener ma non ci riesco. Posto il codice per maggiore chiarezza:
Qualcuno sa dirmi come dovrei fare per farlo funzionare?codice://creao un'istanza della classe XML e ci carico il file var myGalleryXML = new XML(); myGalleryXML.ignoreWhite = true; myGalleryXML.load("gallery.xml"); //carico le variabili della galleria myGalleryXML.onLoad = function() { _root.gallery_x = myGalleryXML.firstChild.attributes.gallery_x; _root.gallery_y = myGalleryXML.firstChild.attributes.gallery_y; _root.gallery_width = myGalleryXML.firstChild.attributes.gallery_width; _root.gallery_height = myGalleryXML.firstChild.attributes.gallery_height; _root.myImages = myGalleryXML.firstChild.childNodes; _root.myImagesTotal = myImages.length; _root.thumb_height = myGalleryXML.firstChild.attributes.thumb_height; _root.thumb_width = myGalleryXML.firstChild.attributes.thumb_width; _root.posX = 0; //richiamo la funzione che carica le thumb callThumbs(); createMask(); scrolling(); }; //creo la funzione che carica le thumb function callThumbs() { _root.createEmptyMovieClip("container_mc",_root.getNextHighestDepth()); container_mc._x = _root.gallery_x; container_mc._y = _root.gallery_y; var clipLoader = new MovieClipLoader(); var preloader = new Object(); clipLoader.addListener(preloader); for (i=0; i<_root.myImagesTotal; i++) { thumbURL = myImages[i].attributes.thumb_url; myThumb_mc = container_mc.createEmptyMovieClip(i, container_mc.getNextHighestDepth() ); myThumb_mc._x = _root.thumb_width*i; //posiziono le immagini tenendo conto di una larghezza fissa clipLoader.loadClip("thumbs/"+thumbURL,myThumb_mc); preloader.onLoadComplete=function(target){ //vorrei posiozionare le thumb in base alla loro larghezza in modo che siano una di fianco all'altra myThumb_mc._x = _root.posX; _root.posX += myThumb_mc._width; //trace(target._x); } } } //creo una maschera di trasparenza da mettere sopra le thumb function createMask() { _root.createEmptyMovieClip("mask_mc",_root.getNextHighestDepth()); mask_mc._x = _root.gallery_x; mask_mc._y = _root.gallery_y; mask_mc.beginFill(0x000000,100); mask_mc.lineTo(_root.gallery_width,0); mask_mc.lineTo(_root.gallery_width,_root.gallery_height); mask_mc.lineTo(0,_root.gallery_height); mask_mc.lineTo(0,0); container_mc.setMask(mask_mc); } //funzione per lo scrolling delle thumb function scrolling() { _root.onEnterFrame = function() { container_mc._x += Math.cos(((mask_mc._xmouse)/mask_mc._width)*Math.PI)*15; if (container_mc._x>mask_mc._x) { container_mc._x = mask_mc._x; } if (container_mc._x<(mask_mc._x-(container_mc._width-mask_mc._width))) { container_mc._x = mask_mc._x-(container_mc._width-mask_mc._width); } }; }
Grazie a tutti in anticipo

Rispondi quotando