Codice PHP:
var path:URLRequest=new URLRequest("canaleMonitor.txt");
var loaderID:URLLoader = new URLLoader(path);
var ID_POSTAZIONE:uint;
//verifica aggiornamento xml ogni 15 minuti
setInterval(confronto, 900000);
loaderID.addEventListener(Event.COMPLETE, assegnaID);
function assegnaID(event:Event):void
{
var ID:URLVariables = new URLVariables(loaderID.data);
ID_POSTAZIONE = ID.idpostazione.split(",");
var url:String = "http://www.****.it/wp-content/monitor/postazioni.php";
var variables:URLVariables = new URLVariables();
variables.stato = 1;
variables.postazione = ID_POSTAZIONE;
var request:URLRequest = new URLRequest(url);
request.data = variables;
try
{
sendToURL(request);
}
catch (e:Error)
{
// handle error here
}
xmlLoader.addEventListener(Event.COMPLETE, xmlLoaded);
xmlLoader.load(new URLRequest("http://www.*****/wp-content/monitor/postazione_"+ID_POSTAZIONE+".xml?"+Math.random()*10000));
}
function xmlLoaded(e:Event):void
{
pianuraXML = new XML(xmlLoader.data);
NumPostTot = pianuraXML.post.length();
//leggo la variabile tempo su pianuraXML
time = pianuraXML. @ time;
//popolo imageArray con URL immagini per gestire componente UILoader
var iA:Number;
for (iA = 0; iA < NumPostTot; iA++)
{
imageArray[iA] = pianuraXML.post.imgUrl[iA];
////trace("imageArray[iA]"+iA+": "+imageArray[iA]);
}
//chiamo un nuovo post e lo richiamo ogni 20 secondi
caricaSuccessiva();
setInterval(caricaSuccessiva, 20000);
}
function caricaSuccessiva()
{
//controllo la variabile che numera Array
if (nPost >= NumPostTot)
{
nPost = 0;
}
////trace("caricaSuccessiva"+nPost);
// preparo il campo eventi
eventiTxt = pianuraXML.post.testo[nPost];
if (eventiTxt == "")
{
eventiTxt = " ";
}
eventi.htmlText = eventiTxt;
//trace("eventi: "+eventiTxt);
//preparo il campo titolo
titolo.alpha=0;
//trace("alpha titolo 0");
titoloTxt = pianuraXML.post.titolo[nPost];
if (titoloTxt == "")
{
titoloTxt = " ";
}
titolo.htmlText = titoloTxt;
//trace("titolo: " + titoloTxt);
//variabili per tween titolo
titolo.width = titolo.textWidth+50;
//preparo il campo fotografo
fotografoTxt = pianuraXML.post.fotografo[nPost];
if (fotografoTxt == "")
{
fotografoTxt = "© Pianura da Scoprire";
}
fotografo.htmlText = fotografoTxt;
//trace("fotografo: "+fotografoTxt);
//preparo il campo urlimage
if (imageArray[nPost] == "")
{
imageArray[nPost] = "http://www.****.it/wp-content/uploads/2011/10/bianca.jpg";
}
//trace("image: "+imageArray[nPost]);
alterna = alterna + 1;
if (alterna > 1)
{
alterna = 0;
}
//trace("alterna: "+alterna);
alternaLoader();
}
function alternaLoader()
{
if (alterna == 1)
{
loadFoto1 = new Loader();
loadFoto1.x=0;
loadFoto1.y=110;
loadFoto1.contentLoaderInfo.addEventListener(Event.COMPLETE, mostraEventi1);
loadFoto1.load(new URLRequest(imageArray[nPost]));
}
else
{
loadFoto2 = new Loader();
loadFoto2.x=0;
loadFoto2.y=110;
loadFoto2.contentLoaderInfo.addEventListener(Event.COMPLETE, mostraEventi2);
loadFoto2.load(new URLRequest(imageArray[nPost]));
}
}
function mostraEventi1(e:Event):void
{
//trace("mostra eventi 1");
if(loadFoto2 != null)
{
removeChild(loadFoto2);
//trace("rimuovo loader 2");
}
larghezzaL1 = e.target.width;
proporzione = 1920 / larghezzaL1;
loadFoto1.scaleX = loadFoto1.scaleY = proporzione;
addChildAt(loadFoto1, 0);
//trace("aggiungo loader 1");
TweenFoto1 = new Tween(loadFoto1,'alpha',None.easeIn,0,1,1,true);
TweenEventi = new Tween(eventi, "x", Strong.easeOut, 1920, 1360, 1, true);
TweenTitolo = new Tween(titolo, 'alpha',None.easeIn,0,1,1,true);
TweenFotografo = new Tween(fotografo, "x", Strong.easeOut, 1920, 1360, 1, true);
TimerEventi();
loadFoto1.contentLoaderInfo.removeEventListener(Event.COMPLETE, mostraEventi1);
nPost++;
}
function mostraEventi2(e:Event):void
{
//trace("mostra eventi 2");
if(loadFoto1 != null)
{
removeChild(loadFoto1);
//trace("rimuovo loader 1");
}
larghezzaL2 = e.target.width;
proporzione2 = 1920 / larghezzaL2;
loadFoto2.scaleX = loadFoto2.scaleY = proporzione2;
addChildAt(loadFoto2, 0);
//trace("aggiungo loader 2");
TweenFoto2 = new Tween(loadFoto2,'alpha',None.easeIn,0,1,1,true);
TweenEventi = new Tween(eventi, "x", Strong.easeOut, 1920, 1360, 1, true);
TweenTitolo = new Tween(titolo, 'alpha',None.easeIn,0,1,1,true);
TweenFotografo = new Tween(fotografo, "x", Strong.easeOut, 1920, 1360, 1, true);
TimerEventi();
loadFoto1.contentLoaderInfo.removeEventListener(Event.COMPLETE, mostraEventi2);
nPost++;
}
function TimerEventi()
{
var myTimer:Timer = new Timer(10000, 1);
myTimer.addEventListener("timer", rimuoviEventi);
myTimer.start();
}
function rimuoviEventi(event:TimerEvent):void
{
TweenEventi = new Tween(eventi, "x", Strong.easeOut, 1560, 1920, 1, true);
TweenFotografo = new Tween(fotografo, "x", Strong.easeOut, 1560, 1920, 1, true);
//trace("rimuovo eventi");
}
function confronto()
{
var url:String = "http://www.*****/wp-content/monitor/postazioni.php";
var variables:URLVariables = new URLVariables();
variables.stato = 1;
variables.postazione = ID_POSTAZIONE;
var request:URLRequest = new URLRequest(url);
request.data = variables;
try
{
sendToURL(request);
}
catch (e:Error)
{
// handle error here
}
xmlLoaderConfronto.addEventListener(Event.COMPLETE, xmlLoadedConfronto);
xmlLoaderConfronto.load(new URLRequest("http://www.*****/wp-content/monitor/postazione_"+ID_POSTAZIONE+".xml?"+Math.random()*10000));
}
function xmlLoadedConfronto(event:Event):void
{
pianuraXMLConfronto = new XML(xmlLoaderConfronto.data);
timeConfronto = pianuraXMLConfronto.@time;
if (timeConfronto > time)
{
//popolo imageArray con URL image Post
var iAConfronto:Number;
NumPostTot = pianuraXMLConfronto.post.length();
for (iAConfronto = 0; iAConfronto < NumPostTot; iAConfronto++)
{
imageArray[iAConfronto] = pianuraXML.post.imgUrl[iAConfronto];
}
pianuraXML = new XML();
pianuraXML = pianuraXMLConfronto;
nPost=0;
time = timeConfronto;
}
}
...seguono altre azioni per la gestione dell'orologio e della grafica...