AS3 Beginners. Problemas Sintaxis

6 views
Skip to first unread message

Comet!

unread,
Feb 17, 2009, 5:26:56 AM2/17/09
to ASNativos - Lista de Actionscript
Otra de beginner:

Estoy haciendo esto: Crear muchos círculos y ponerlos en pantalla

[CODE]

function crearCirculo(radio:uint, color:uint = 0x1A579D) :Shape
{
radio = Math.random() * 75;
var forma:Shape = new Shape();
forma.graphics.beginFill(color);
forma.graphics.drawCircle(radio/2,radio/2,radio);
forma.graphics.endFill();
return forma;
}

var c1:Shape = crearCirculo(Math.random() * 75);
var c2:Shape = crearCirculo(Math.random() * 75);
var c3:Shape = crearCirculo(Math.random() * 75);
var c4:Shape = crearCirculo(Math.random() * 75);
var c5:Shape = crearCirculo(Math.random() * 75);

vacio_mc.addChild(c1);
vacio_mc.addChild(c2);
vacio_mc.addChild(c3);
vacio_mc.addChild(c4);
vacio_mc.addChild(c5);

[/CODE]

Me interesa trabajar con Arrays como hacía en AS2, algo así pero no
tira:

[CODE]

function crearCirculo(radio:uint, color:uint = 0x000000) :Shape
{
radio =75;
var forma:Shape = new Shape();
forma.graphics.beginFill(color);
forma.graphics.drawCircle(radio/2,radio/2,radio);
forma.graphics.endFill();
return forma;
}

var c1:Shape = crearCirculo(75);
var c2:Shape = crearCirculo(75);
var c3:Shape = crearCirculo(75);
var c4:Shape = crearCirculo(75);
var c5:Shape = crearCirculo(75);

var arrayFormas:Array=[c1,c2,c3,c4,c5];

for(var i:Number=0; i<arrayFormas.lenght; i++)
{
vacio_mc.addChild(arrayFormas[i]);
}

[/CODE]

:(

José Tomás Tocino García

unread,
Feb 17, 2009, 5:34:04 AM2/17/09
to asna...@googlegroups.com
Ten cuidado, tienes un typo en el for de abajo. Es "length", no "lenght".

Cambiando eso ya salen.
--
José Tomás Tocino García aka. TheOm3ga
http://www.om3.com.es

pedro alpera

unread,
Feb 17, 2009, 5:36:29 AM2/17/09
to asna...@googlegroups.com
Tienes mal puesto length :)

Comet!

unread,
Feb 17, 2009, 7:31:34 AM2/17/09
to ASNativos - Lista de Actionscript
Pfff, estoy ciego. Gracias!

Hay manera de no escribir estas líneas en una sola?

var c1:Shape = crearCirculo(Math.random() * 75);
var c2:Shape = crearCirculo(Math.random() * 75);
var c3:Shape = crearCirculo(Math.random() * 75);
var c4:Shape = crearCirculo(Math.random() * 75);
var c5:Shape = crearCirculo(Math.random() * 75);

??????????

Cay

unread,
Feb 17, 2009, 7:42:10 AM2/17/09
to asna...@googlegroups.com
Puedes hacer algo asi:

for(var i=0;i<5;i++) {
  miarray.push(crearCirculo(Math.random() * 75));
}

Y por cierto, si tas en AS3, lo que tenias antes (lo del lenght) te debiera haber tirado un error... tenlos siempre en cuenta ;)

Saludos...

Iván

unread,
Feb 17, 2009, 7:42:16 AM2/17/09
to asna...@googlegroups.com
Yo lo haría con Arrays. Así a pelo

var circulos_array:Array = new Array();

for(var i=1;i<=5;i++){
circulos_array.push(crearCirculo(Math.random()*75));
Reply all
Reply to author
Forward
0 new messages