Ver Mensaje Individual
  #1 (permalink)  
Antiguo 16/08/2010, 05:21
_WILCO_
 
Fecha de Ingreso: marzo-2005
Mensajes: 26
Antigüedad: 19 años, 1 mes
Puntos: 0
Mover mis patos simplificando el código

Buenos días, tengo 4 patos que se mueven al pulsar botones con este código.

//importamos el tween
import mx.transitions.Tween;
import mx.transitions.easing.*;

bot1.onRelease = function () {

var miTween:Tween = new Tween(pato1, "_x", Strong.easeOut, pato1._x, pato1._x+150, 1, true);

}

bot2.onRelease = function () {

var miTween:Tween = new Tween(pato2, "_x", Strong.easeOut, pato2._x, pato2._x+150, 1, true);

}

bot3.onRelease = function () {

var miTween:Tween = new Tween(pato3, "_x", Strong.easeOut, pato3._x, pato3._x+150, 1, true);

}

bot4.onRelease = function () {

var miTween:Tween = new Tween(pato4, "_x", Strong.easeOut, pato4._x, pato4._x+150, 1, true);

}

Es simple, pero necesito simplificar el código. Para ello, intento programarlo en arrays, pero no me funciona:

//importamos el tween
import mx.transitions.Tween;
import mx.transitions.easing.*;

var bot = [bot1,bot2,bot3,bot4]
var pato = [pato1, pato2, pato3, pato4]


bot[i].onRelease = function () {

var miTween:Tween = new Tween(pato[i], "_x", Strong.easeOut, pato[i]._x, pato[i]._x+150, 1, true);
trace (bot[i]);

}

¿Qué estoy haciendo mal? Es por el uso de [i], ¿verdad?

Les agradezco mucho la respuesta.

Saludos.