Este es el codigo con el que trabajo:
Primero creo las variables de la anchura y la altura, posteriormente creo la funcion que me servira par escalar la imágen.
Código :
var altura_Maxima_Foto: Number = 43;
var anchura_Maxima_Foto: Number = 73;
function escalarImagen (alto: Number, ancho: Number): Object{
if (alto > altura_Maxima_Foto){
if (ancho <= anchura_Maxima_Foto){
var coeficiente: Number = alto / altura_Maxima_Foto;
var altura: Number = altura_Maxima_Foto;
var anchura: Number = ancho / coeficiente;
} else {
var coeficiente: Number = alto / altura_Maxima_Foto;
var altura: Number = altura_Maxima_Foto;
var anchura: Number = ancho / coeficiente;
if (anchura > anchura_Maxima_Foto){
coeficiente = ancho / anchura_Maxima_Foto;
anchura = anchura_Maxima_Foto;
altura = alto / coeficiente;
}
}
} else {
if (ancho > anchura_Maxima_Foto){
var coeficiente: Number = ancho / anchuraMaximaFoto;
var anchura: Number = anchura_Maxima_Foto;
var altura: Number = alto / coeficiente;
}
}
return {ancho:anchura,alto:altura};
}
luego cargo el xml, que recibe una ruta de una imagen y un texto;
Código :
miXML = new XML();
miXML.ignoreWhite = true;
noticia_txt.html = true;
noticia_txt.multiline = true;
noticia_txt.autoSize = true;
noticia_txt.wordWrap = true;
noticia_txt.descent = true;
// -- cargo XML
miXML.onLoad = function(succes) {
if (succes) {
noticia_txt.text= miXML.firstChild.childNodes[0].childNodes[0].attributes.cabecera;
imagen.loadMovie (miXML.firstChild.childNodes[0].childNodes[0].attributes.foto);
escalarImagen();
}
}y finalmente intento cargar en un clip la imagen y escalarla.
Código :
this.createEmptyMovieClip("imagen", 11);
imagen.onLoad=function(){
if (imagen ._width != 0) {
if (imagen._height > altura_Maxima_Foto || imagen._width > anchura_Maxima_Foto){
var nuevoTamanio: Object = escalarImagen(imagen._height, imagen._width);
imagen._width = nuevoTamanio.ancho;
imagen._height = nuevoTamanio.alto;
escalarImagen();
}
}
}
miXML.load("agenda.xml");
pero solo carga la imagen.
