Prototipo dibujar rectángulo
Enlaces recomendados, mis protos | Enero 26th, 2004Versión para imprimir
Es un poco chorras, pero bueno ![]()
// dibujar_rectangulo
// tonilopez
// posx,poy = posición inicial en los ejes x,y
// ancho = ancho del rectangulo
// alto = alto del rectangulo
// ancho_borde
// color_borde
// alfa_borde
// color_relleno
// alfa_relleno
MovieClip.prototype.dibujar_rectangulo = function(pos_x, pos_y, ancho, alto, ancho_borde, color_borde, alfa_borde, color_relleno, alfa_relleno) {
// –
this.px = pos_x;
this.py = pos_y;
this.an = ancho;
this.al = alto;
this.ab = ancho_borde;
this.alb = alfa_borde;
this.cr = color_relleno;
this.ar = alfa_relleno;
// –
this.createEmptyMovieClip("papel", 1000);
with (papel) {
beginFill(cr, ar);
lineStyle(this.ab, this.cb, this.alb);
moveTo(px, py);
lineTo(px+an, py);
lineTo(px+an, py+al);
lineTo(px, py+al);
lineTo(px, py);
endFill();
}
};
dibujar_rectangulo(0, 0, 100, 100, 1, “0x000000″, 100, “0xCCCCCC", 100);
Enero 30th, 2004 at 4:56 pm
Muy útil el proto, toni. Ahora lo iba a probar para un proyecto cuando me he dado cuenta de que (al menos a mi) no me funcionaba.
He cambiado el codigo por este y sí que funciona:
MovieClip.prototype.dibujar_rectangulo = function(pos_x, pos_y, ancho, alto, ancho_borde, color_borde, alfa_borde, color_relleno, alfa_relleno) {
// –
this.px = pos_x;
this.py = pos_y;
this.an = ancho;
this.al = alto;
this.ab = ancho_borde;
this.alb = alfa_borde;
this.cr = color_relleno;
this.ar = alfa_relleno;
// –
this.createEmptyMovieClip("papel", 1000);
with (this.papel) {
beginFill(this.cr, this.ar);
lineStyle(this.ab, this.cb, this.alb);
moveTo(this.px, this.py);
lineTo(this.px+this.an, this.py);
lineTo(this.px+this.an, this.py+this.al);
lineTo(this.px, this.py+this.al);
lineTo(this.px, this.py);
endFill();
}
};
Antes de cambiarlo me salia un error por el output que decia que no se podia ejecutar el “with” porque el objeto no estaba definido. Ahora se dibuja bien.
Enga, un saludo!
Enero 30th, 2004 at 5:04 pm
Ah, se me olvidaba, falta definir el color del borde dentro del proto:
//-
this.px = pos_x;
this.py = pos_y;
this.an = ancho;
this.al = alto;
this.ab = ancho_borde;
this.alb = alfa_borde;
this.cr = color_relleno;
this.ar = alfa_relleno;
this.cb = color_borde; // << este no estaba antes
// –
Saludos!!
Febrero 2nd, 2004 at 10:19 am
Pues que curioso Dani, por que a mi el script me funciona perfectamente, cierto es que olvidé poner em argumento color borde, pero al no existir, automáticamente es 0x000000
saludos.toni