Google Web after-hours

Contador en flash JSFL Traductor

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);

3 Responses to 'Prototipo dibujar rectángulo'

  1. dani Says:

    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!

  2. dani Says:

    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!!

  3. tonilopez Says:

    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