Función para crear marcos con esquinas redondeadas
Tuesday December 18th 2007, 1:37 pm
Filed under: Flash

Hace poco he tenido que crear esta función en el trabajo para crear un cuadrado con esquinas redondeadas.

Actionscript:
  1. crearMarco(10, 10, Stage.width-20, Stage.height-20, 10, 0x000000, 2, 0xFFCC00);
  2.  
  3. function crearMarco(x:Number, y:Number, w:Number, h:Number, r:Number, borderColor:Number, borderWidth:Number, fillColor:Number)
  4. {
  5.     this.createEmptyMovieClip("marco_mc", 1);
  6.    
  7.     marco_mc._x = x;
  8.     marco_mc._y = y;
  9.    
  10.     with (marco_mc)
  11.     {
  12.         lineStyle(borderWidth, borderColor, 100);
  13.         beginFill(fillColor);
  14.         moveTo(r, 0);
  15.         lineTo(w - r, 0);
  16.         curveTo(w, 0, w, r);
  17.         lineTo(w, h - r);
  18.         curveTo(w, h, w - r, h);
  19.         lineTo(r, h);
  20.         curveTo(0, h, 0, h - r);
  21.         lineTo(0, r);
  22.         curveTo(0, 0, r, 0);
  23.         endFill();
  24.     }
  25. }

Es especialmente útil a la hora de hacer máscaras en tiempo de ejecución ;)

También dejo el FLA para descargar.

Descargar función marcos redondeados