Comunidad de diseño web y desarrollo en internet online

ayuda con imagen cargada en xml y luego escalarla

Citar            
MensajeEscrito el 29 Jun 2009 07:57 pm
Hola a todos. Necesito ayuda con un script que intento desarrollar para cargar una imagen de un xml y luego escalarla para unas medidas.

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.

Por Idearis

19 de clabLevel



 

firefox
Citar            
MensajeEscrito el 29 Jun 2009 08:32 pm
creo q el problem es k al cargar la imagen no te tome inmediatamente los valores W H, usa una precarga de la imagen y al terminar entonces la dimensionas

veen la ayudad e flash, el objeto moviecliploader, te puede ayudar de mucho, o si te lo avientas a patin ;) usando onenterframe y al terminar carga bytesloaded==bytestotal entonces.... dimensiona

Por comicSans

Claber

151 de clabLevel



 

msie7
Citar            
MensajeEscrito el 29 Jun 2009 10:06 pm
no entiendo

¿o si te lo avientas a patin ;) usando onenterframe y al terminar carga bytesloaded==bytestotal entonces.... dimensiona?

he probado a crar una precarga y redimensionar con el onEnterFrame

Código :

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();
   }
}
this.createEmptyMovieClip("imagen", 11);
this.attachMovie("porcentaje", "porcentaje", 11, {_x:imagen._x, _y:imagen._y});
imagen.onEnterFrame=function(){
   var cargado: Number = imagen.getBytesLoaded();
   var total: Number = imagen.getBytesTotal();
      if (!isNaN(cargado/total)){
         imagen.porcentaje.valor.text = (100*Math.round(cargado/total)) + " %";
      }
      if (imagen._width != 0 && cargado == total){
         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;
         }
         
         imagen.porcentaje.removeMovieClip();
         delete imagen.onEnterFrame;
      }
   }

   
miXML.load("agenda.xml"); 


Pero ahora no me carga la imagen

Por Idearis

19 de clabLevel



 

firefox
Citar            
MensajeEscrito el 30 Jun 2009 07:41 pm
Hola. Estas usando el mismo Depth para imagen y porcentaje? (11)

Bueno, yo iria por pasos, primero cargo el xml, luego inicio la carga de la imagen y luego llamo funcion enterframe, mmmm... algo asi:

Código ActionScript :

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);
imagen._alpha = 0; // para no ver objetos raros en Stage, no?
// A cargar el xml llamas cargaIMG para empezar carga del imagen y dimensiones del obj
cargaIMG();
}
}

this.createEmptyMovieClip("imagen", 11);
// DONDE ESTAS ATANDO PORCENTAJE EN IMAGEN O EN THIS ?!
this.attachMovie("porcentaje", "porcentaje", 11, {_x:imagen._x, _y:imagen._y}); // cambia Depth: 11 -> 12
// entonces....
imagen.attachMovie("porcentaje", "porcentaje", 1); // sera? no lo he intentado
// aqui el problem es k si atas porcentaje dentro de imagen lo vas a escalar tambien

function cargaIMG() {
imagen.onEnterFrame=function(){
var cargado: Number = this.getBytesLoaded();
var total: Number = this.getBytesTotal();
   if (!isNaN(cargado/total))
   {
//   etc...
   }
}
}

   
miXML.load("agenda.xml"); 

ojala puedas arreglarlo ;) Salu2!

Por comicSans

Claber

151 de clabLevel



 

msie7
Citar            
MensajeEscrito el 02 Jul 2009 09:27 pm
Gracias por la ayuda de antemano.

Pero he probado el codigo y sigue sin cargar la imagen

Código ActionScript :

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};
}
//creo el clip para contener las imagenes
this.createEmptyMovieClip("imagen", 11); 
// realizo la precarga
imagen.attachMovie("porcentaje", "porcentaje", 12); //distinto depht
// no me preocupa que se escale 
 
function cargaIMG() { 
imagen.onEnterFrame=function(){ 
   var cargado: Number = this.getBytesLoaded(); 
   var total: Number = this.getBytesTotal(); 
   if (!isNaN(cargado/total)) 
         imagen.porcentaje.valor.text = (100*Math.round(cargado/total)) + " %";
      }
      if (imagen._width != 0 && cargado == total){
         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;
         }
         
         imagen.porcentaje.removeMovieClip();
         delete imagen.onEnterFrame;
      }
   }
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); 
      imagen._alpha = 0; // para no ver objetos raros en Stage, no? 
      // A cargar el xml llamo cargaIMG para empezar carga del imagen y dimensiones del obj 
      cargaIMG(); 
   } 
}   
miXML.load("agenda.xml"); 



Donde puede estar al problema? Cual es el camino hacia la luz?

Por Idearis

19 de clabLevel



 

firefox

 

Cristalab BabyBlue v4 + V4 © 2011 Cristalab
Powered by ClabEngines v4, HTML5, love and ponies.