Ciao a tutti!
Premetto che uso pochissimo (e male) Flash... :master:
Mi è stata fatta la richiesta di creare un file che mostrasse in sequenza alcune immagini.
Ho trovato un file .fla già pronto, che richiedeva solo poche modifiche. Le immagini (presenti in una certa cartella) vengono lette da un file XML.
Visto che ci sarà l'esigenza di aggiornare le immagini, ho pensato che il modo più pratico fosse quello di far aggiornare automaticamente il file XML.
Il file XML è questo:
codice:
<?xml version="1.0"?>
<RSS PAUSE="4000">
<IMAGE TRANSITION="1">i/panoramiche/foto_1.jpg</IMAGE>
<IMAGE TRANSITION="1">i/panoramiche/foto_2.jpg</IMAGE>
<IMAGE TRANSITION="1">i/panoramiche/foto_3.jpg</IMAGE>
<IMAGE TRANSITION="1">i/panoramiche/foto_4.jpg</IMAGE>
</RSS>
Ho creato un file ASP che va a leggere il contenuto della cartella "panoramiche" e poi mi salva il file XML opportunamente aggiornato.
Fin qui tutto bene.
E adesso i problemi...
1. Il file di Flash "vuole" che il file XML stia nella sua stessa cartella. Non sono riuscito a dirgli di leggere il file XML da un'altra parte. Come si fa?
Visto che il file XML deve trovarsi in una cartella con i diritti di scrittura (la cartella "public", se facciamo riferimento alla struttura dei siti di un noto hoster), anche il file .swf dovrà trovarsi lì. Preferirei metterlo in un'altra cartella.
2. Se richiamo da broswer il file di Flash: www.miosito.it/public/file.swf, il file viene mostrato e funziona tutto bene (si vedono le immagini). Se, invece, inserisco il file in un file html o asp (che ovviamente si trova in un'altra cartella), non si vedono le immagini.
3. Com'è possibile modificare l'AS in modo che le immagini vengano mostrare in modo casuale? Immagino che si debba usare una funzione random, ma non so né come, né dove.
Questo è l'AS che c'è nel file di Flash.
codice:
#initclip
ImageFader = function () { this.__init__();};
ImageFader.prototype = new MovieClip();
// ** init class ** //
ImageFader.prototype.__init__ = function() {
this._xscale = 100;
this._yscale = 100;
this.bounding_box.unloadMovie();
this._fader_.unloadMovie();
this._dataProvider = new Array();
this._count = 0;
this._depth = 1;
this._isLoaded = -1;
if (this._S_) {
clearInterval(this._S_);
}
if (this._xmlfile != "") {
this.loadXML(this._xmlfile);
}
};
// *** load the external xml ** //
ImageFader.prototype.loadXML = function(x) {
var _xml = new XML();
_xml.ignoreWhite = true;
_xml.path = this;
_xml.load("/public/images.xml");
_xml.onLoad = function() {
for (var a = 0; a<this.firstChild.childNodes.length; a++) {
var _trans = this.firstChild.childNodes[a].attributes.TRANSITION;
var _pause = this.firstChild.attributes.PAUSE;
var _img = this.firstChild.childNodes[a].firstChild.nodeValue;
this.path._dataProvider.push({img:_img, transition:_trans, pause:_pause});
}
this.path.startFading();
delete this;
};
};
// ** start fading procedure ** //
ImageFader.prototype.startFading = function() {
if (this._dataProvider.length>0) {
this.makeFader(true);
}
};
// ** load images ** //
ImageFader.prototype.makeFader = function(first) {
this._isLoaded = -1;
this._tmp = this.attachMovie("ImageLoader", "ImageLoader"+this._depth, this._depth++);
this._old1 = this['ImageLoader'+(this._depth-1)];
this._old2 = this['ImageLoader'+(this._depth-2)];
this._tmp.loadHandler("isLoaded", this._count);
this._tmp.autoStart = false;
this._tmp.transition = this._dataProvider[this._count].transition;
this._tmp.loadImage(this._dataProvider[this._count].img);
this._t1 = getTimer();
this.onEnterFrame = function() {
this._t2 = getTimer();
if ((this._t2-this._t1)>this._dataProvider[this._count].pause || first == true) {
if (this._isLoaded == this._count || this._isLoaded == 1 && this._count == 0) {
delete this.onEnterFrame;
this._tmp.start();
this._old1.fadeOut();
this._old2.removeMovieClip();
if (this._count+1<this._dataProvider.length) {
this._count++;
this.makeFader();
return;
} else {
if (this._loop == true) {
this._count = 0;
this.makeFader();
}
}
}
}
};
};
// ** which has been loaded ? ** //
ImageFader.prototype.isLoaded = function(num) {
this._isLoaded = num;
};
Object.registerClass("ImageFader", ImageFader);
#endinitclip
Grazie!