stop();
Stage.align = “t”;
Stage.scaleMode = “noScale”;
Stage.showMenu = false;
import it.sephiroth.XML2Object;
var listaIncrementos:Array = Array(1, 5, 10, 20, 50, 100, 200, 500);
var posicionListaIncrementos = 0;
var listaTiempo:Array = Array();
var listacontTiempo:Array = Array();
var listaLatitudesRaw:Array = Array();
var listaLongitudesRaw:Array = Array();
var listaNombres:Array = Array();
var minlatitud:Number = 0;
var minlongitud:Number = 0;
var maxlatitud:Number = 0;
var maxlongitud:Number = 0;
var radioTierra = 6371000;
var miCounter:Number = 0;
var maxPuntos:Number = 0;
var incremento:Number = 1;
var horas:Number = 0;
var minutos:Number = 0;
var segundos:Number = 0;
var contador:Number = 0;
var pausa:Boolean = false;
var xLine2 = 0;
var yLine2 = 0;
var banderaPunto:Boolean = false;
var puntosActuales = 0;
var varPasada:Boolean = false;
cargaXml();
////////////////////////////////////////////////////////////////////////
//
function cargaXml() {
myXML = new XML();
myXML.load(“la_pausa.xml”);
myXML.onLoad = function() {
var xml_loader:XML2Object = new XML2Object();
xml = xml_loader.parseXML(this);
sacaInfo();
};
}
//
function sacaInfo() {
lenWpt = xml.lapausa.gpx.length;
for (i=0; i<lenWpt; i++) {
latitud = xml.lapausa.gpx[i].wpt.attributes.lat;
longitud = xml.lapausa.gpx[i].wpt.attributes.lon;
nombrePunto = xml.lapausa.gpx[i].wpt.name.data;
tiempo = substring(xml.lapausa.gpx[i].time.data, 12, 13);
contTiempo = tiempoaSegundos(tiempo);
listacontTiempo.push(contTiempo);
if (i == 0) {
minLatitud = latitud;
minLongitud = longitud;
maxLatitud = latitud;
maxLongitud = longitud;
}
if (latitud>maxLatitud) {
maxLatitud = latitud;
}
if (longitud>maxLongitud) {
maxLongitud = longitud;
}
if (latitud<minLatitud) {
minLatitud = latitud;
}
if (longitud<minLongitud) {
minLongitud = longitud;
}
listaLatitudesRaw.push(latitud);
listaLongitudesRaw.push(longitud);
listaNombres.push(nombrePunto);
}
creacion();
creaCounter();
}
//
function tiempoaSegundos(tiempo:String):Number {
var listaElementos:Array = tiempo.split(“:”);
var horas:Number = Number(listaElementos[0]);
var minutos:Number = Number(listaElementos[1]);
var segundos:Number = Number(substring(listaElementos[2], 0, 2));
var totalSegundos = segundos+(minutos*60)+(horas*3600);
//trace(“tiempo:”+tiempo+”, totalSegundo:”+totalSegundos);
return totalSegundos;
}
//
function segundosaTiempo(tiempo:Number):String {
var horas = Math.floor(tiempo/3600);
var minutos = Math.floor((tiempo%3600)/60);
var segundos = Math.floor((tiempo%3600)%60);
//trace(“tiempo:”+tiempo+”, totalSegundo:”+totalSegundos);
var totalTiempo:String = String(dobleDigito(horas)+”:”+dobleDigito(minutos)+”:”+dobleDigito(segundos));
return totalTiempo;
}
//
function resetTimer() {
//pausa = true;
contador = 0;
segundos = 0;
minutos = 0;
horas = 0;
maxPuntos = 0;
}
//
function creaCounter() {
attachMovie(“counter”,”counter”,getNextHighestDepth());
counter._y = 0;
counter._x = Stage.width-50;
counter.onEnterFrame = function() {
if (pausa == false) {
contador += incremento/30;
segundos += incremento/30;
//segundos += incremento;
if (segundos>59) {
segundos = 0;
minutos = minutos+1;
}
if (minutos>59) {
minutos = 0;
horas = horas+1;
}
if (horas == 24) {
pausa = true;
}
}
counter.contador_txt.text = dobleDigito(horas)+”:”+dobleDigito(minutos)+”:”+dobleDigito(Math.floor(segundos));
actualizaInformacionGeneral();
};
}
//
function dobleDigito(num):String {
numero = num.toString().split(“”);
if (numero.length<2) {
numeroDoble = “0″+numero;
} else {
numeroDoble = num;
}
return numeroDoble;
}
//
function scaleVar(variable, low, high, tarLow, tarHigh):Number {
targValDif = tarHigh-tarLow;
valDif = high-low;
proporcion = targValDif/valDif;
maped = tarLow+((variable-low)*proporcion);
//trace(variable+”,”+ targValDif+”,”+ valDif+ “,”+proporcion+”,”+ maped);
return maped;
}
//
function creacion() {
latRadians = 0;
lonRadians = (maxLongitud-minLongitud)*Math.PI/180;
var a = Math.sin(latRadians/2)*Math.sin(latRadians/2)+Math.cos(minLatitud*Math.PI/180)*Math.cos(minLatitud*Math.PI/180)*Math.sin(lonRadians/2)*Math.sin(lonRadians/2);
var c = 2*Math.atan2(Math.sqrt(a), Math.sqrt(1-a));
var distanciaLongitud = radioTierra*c;
latRadians = (maxLatitud-minLatitud)*Math.PI/180;
lonRadians = 0;
var a = Math.sin(latRadians/2)*Math.sin(latRadians/2)+Math.cos(minLatitud*Math.PI/180)*Math.cos(maxLatitud*Math.PI/180)*Math.sin(lonRadians/2)*Math.sin(lonRadians/2);
var c = 2*Math.atan2(Math.sqrt(a), Math.sqrt(1-a));
var distanciaLatitud = radioTierra*c;
attachMovie(“marco”,”marco”,getNextHighestDepth());
marco._y = 0;
marco._x = 0;
canvasx = Stage.width;
canvasy = distanciaLongitud*Stage.width/distanciaLatitud;
marco._width = canvasx;
marco._height = canvasy;
creaInfoGeneral(canvasy);
for (l=0; l<lenWpt; l++) {
latRadians = 0;
lonRadians = (listaLongitudesRaw[l]-minLongitud)*Math.PI/180;
var a = Math.sin(latRadians/2)*Math.sin(latRadians/2)+Math.cos(minLatitud*Math.PI/180)*Math.cos(minLatitud*Math.PI/180)*Math.sin(lonRadians/2)*Math.sin(lonRadians/2);
var c = 2*Math.atan2(Math.sqrt(a), Math.sqrt(1-a));
var latitud = radioTierra*c;
latMaped = scaleVar(latitud, 0, distanciaLongitud, 0, canvasy);
latRadians2 = (listaLatitudesRaw[l]-minLatitud)*Math.PI/180;
lonRadians2 = 0;
var a2 = Math.sin(latRadians2/2)*Math.sin(latRadians2/2)+Math.cos(minLatitud*Math.PI/180)*Math.cos(maxLatitud*Math.PI/180)*Math.sin(lonRadians2/2)*Math.sin(lonRadians2/2);
var c2 = 2*Math.atan2(Math.sqrt(a2), Math.sqrt(1-a2));
var longitud = radioTierra*c2;
lonMaped = scaleVar(longitud, 0, distanciaLatitud, 0, canvasx);
creaPuntos(l,listacontTiempo[l],lonMaped,latMaped);
if (l == lenWpt-1) {
creaLineas();
}
}
}
//
function creaInfoGeneral(posInfoY) {
attachMovie(“informacionGeneral”,”informacionGeneral”,getNextHighestDepth());
informacionGeneral._y = posInfoY+5;
informacionGeneral.minLatitud.text = minLatitud;
informacionGeneral.minLongitud.text = minLongitud;
informacionGeneral.maxLatitud.text = maxLatitud;
informacionGeneral.maxLongitud.text = maxLongitud;
informacionGeneral.totalPuntos.text = lenWpt;
informacionGeneral.playPause.onRelease = function() {
if (pausa == false) {
pausa = true;
} else if (pausa == true && horas<24) {
pausa = false;
} else if (pausa == true && horas == 24) {
resetTimer();
pausa = false;
}
};
informacionGeneral.subirAceleracion.onRelease = function() {
if (posicionListaIncrementos != 7) {
incremento = listaIncrementos[posicionListaIncrementos+1];
posicionListaIncrementos += 1;
}
};
informacionGeneral.bajarAceleracion.onRelease = function() {
if (posicionListaIncrementos != 0) {
incremento = listaIncrementos[posicionListaIncrementos-1];
posicionListaIncrementos -= 1;
}
};
}
//
function actualizaInformacionGeneral() {
informacionGeneral.contadorTiempo.text = dobleDigito(horas)+”:”+dobleDigito(minutos)+”:”+dobleDigito(Math.floor(segundos));
informacionGeneral.aceleracion.text = incremento;
informacionGeneral.puntosActuales.text = maxPuntos;
if (pausa == true) {
informacionGeneral.playPause.gotoAndStop(“pausa”);
} else {
informacionGeneral.playPause.gotoAndStop(“play”);
}
}
function creaPuntos(index, tiempo, miX, miY) {
attachMovie(“point”,”point”+index,getNextHighestDepth());
miNodo = this["point"+index];
miNodo._y = miY;
miNodo._x = miX;
miNodo.tiempo = tiempo;
miNodo.contCoord._visible = false;
miNodo.contCoord.coordenadas.autoSize = true;
miNodo.contCoord.coordenadas.text = listaNombres[index]+”, tiempo:”+segundosaTiempo(miNodo.tiempo)+”, y:”+Math.floor(miY)+”, x:”+Math.floor(miX);
miNodo._alpha = 0;
miNodo._visible = false;
miNodo.tiempoInterno = 0;
miNodo.estadoActual = false;
miNodo.estadoAnterior = false;
miNodo.onEnterFrame = function() {
if (this.tiempo<contador) {
tiempoInterno++;
this._visible = true;
this.estadoActual = true;
if (this.estadoActual != this.estadoAnterior) {
this.estadoAnterior = true;
maxPuntos++;
creaLineas();
//trace(maxPuntos);
}
if (tiempoInterno<8) {
if (this._alpha<100) {
this._alpha += 10;
}
} else {
if (this._alpha>30) {
this._alpha -= 5;
//trace(“reduciendo alpha”);
}
}
} else {
tiempoInterno = 0;
this._visible = false;
this._alpha = 0;
this.estadoActual = false;
this.estadoAnterior = false;
}
};
miNodo.onRollOver = function() {
this.contCoord._visible = true;
};
miNodo.onRollOut = function() {
this.contCoord._visible = false;
};
}
/////////////////////////////////////////////////////////////
//
keyListener = new Object();
keyListener.onKeyDown = function() {
if (Key.getCode() == 32) {
if (pausa == false) {
pausa = true;
} else if (pausa == true && horas<24) {
pausa = false;
} else if (pausa == true && horas == 24) {
resetTimer();
pausa = false;
}
}
if (Key.getCode() == 37) {
resetTimer();
}
};
Key.addListener(keyListener);