Bien chicos, lo de la OOP me interesa. Yo que vengo de la programaci�n en Java, muchas 
veces he pensado en utilizar la OOP en Flash, pero no s� c�mo aplicarla.
Supongamos pues que tengo una aplicaci�n donde carga mediante xml una serie de fotos 
en miniatura(thumbnails) y que luego realizo la acciones que deseo con ellas.
A nivel de programaci�n funcional, las funciones se podrian resumir de esta forma:

funtion cargarXML() {
catalogoXML = new XML();
catalogoXML.ignoreWhite = true;

catalogoXML.onLoad = function(ok) {
 if (!ok) {
  return false;
 }
 //no ha cargado correctamente, salir de la funci�n. 
 var nodo = this.firstChild;
  var hijo = nodo.childNodes;
  for (var i = 0; i<hijo.length; i++) {
  comedor = hijo[i].firstChild;
   cargarImagen(comedor.attributes.url);
 }
};
catalogoXML.load("dormitorios/dormitorios.xml");
limpiaXML();
}

var nimagen = 0;
var distancia = 0;
var destino = imagenes._y;
//Variables para las flechas de movimiento
var minimo = imagenes._y;
var maximo = mascara._height+mascara._y-1;
//------------------------------------------
//Funciones
//------------------------------------------
function limpiaXML() {
 delete nodo;
 delete hijo;
 delete comedor;
 delete catalogoXML;
}
function cargarImagen(imagen) {
 clipN = imagenes.createEmptyMovieClip("img_"+nimagen, nimagen++);
 contenedor = clipN.createEmptyMovieClip("contenedor", 1);
 contenedor.loadMovie(imagen);
  clipN._y = distancia;
 distancia += 40;
 
 clipN.onPress = function() {
  this._alpha = 70;
 };

 if (imagenes._y>=minimo) {
  subir._alpha = 10;
  subir.enabled = false;
 }
 if (imagenes._y>=maximo) {
  bajar._alpha = 10;
  bajar.enabled = false;
 }
}
bajar.onPress = function() {
 imagenes.bajar();
 bajar.enabled = false;
 //desactivo el bot�n moment�neamente
};
subir.onPress = function() {
 imagenes.subir();
 subir.enabled = false;
};
MovieClip.prototype.bajar = function() {
 destino = imagenes._y-40;
 //posicion destino
 this.onEnterFrame = function() {
  imagenes._y += Math.floor((destino-imagenes._y)/3);
  //funci�n de easing
  if (imagenes._y == destino) {
   delete this.onEnterFrame;
   bajar.enabled = true;
   //Controlo si deben aparecer las flechas de desplazamiento
   if (imagenes._y<=minimo) {
    subir._alpha = 100;
    subir.enabled = true;
   }
   if ((imagenes._y+imagenes._height)<=maximo) {
    bajar._alpha = 10;
    bajar.enabled = false;
   }
  }
 };
};
MovieClip.prototype.subir = function() {
 destino = imagenes._y+40;
 this.onEnterFrame = function() {
  imagenes._y += Math.ceil((destino-imagenes._y)*1/3);
  if (imagenes._y == destino) {
   delete this.onEnterFrame;
   subir.enabled = true;
   if (imagenes._y>=minimo) {
    subir._alpha = 10;
    subir.enabled = false;
   }
   if ((imagenes._y+imagenes._height)>=maximo) {
    bajar._alpha = 100;
    bajar.enabled = true;
   }
  }
 };
};

Bien, esto pasado a POO, se podria realizar haciendo una clase Imagen, donde tuviera 
como m�todos, cargarXML, cargarImagen,..

Alguien puede ponernos un ejemplo de c�mo seria �sto a nivel de POO?

<!-------------------------------
Lista ASNativos:
subscripciones/desubscripciones
http://www.sidedev.net/asnativos
-------------------------------->

Responder a