Multiples “Event Handlers” en flash

18 05 2007

Es posible hacer que un evento, por ejemplo "onEnterFrame", ejecute varias funciones. Aquí muestro como.

El método que utilizo es bastante tonto. Lo uso cuando necesito crear una clase que agrega cierta funcionalidad al evento "onEnterFrame"(como actualizar una variable determinada) y no quiero perder el handler que tiene el objeto.

Básicamente creo un array de funciones en el objeto y voy agregando funciones al mismo, para despues ejecutarlas en secuencia:

Actionscript:
  1. this.circulo.onEnterFrame = function() {
  2.     trace('test');
  3.     circulo._y++;
  4. };
  5. this.circulo.arrayf = new Array(this.circulo.onEnterFrame, function () {
  6.     circulo._x++;
  7. });
  8. this.circulo.onEnterFrame = function() {
  9.     var i:Number;
  10.     for (i=0; i<this.arrayf.length; i++) {
  11.         this.arrayf[i]();//acá ejecuto las funciones en orden, noten el doble paréntesis después de los brackets de la matriz.
  12.     }
  13. };

Con esto genero un pool de funciones a las que puedo agregar pre y post procesamiento.


Acciones

Informacion

Deje un comentario

usted puede usar estos tags : <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

*
To prove you're a person (not a spam script), type the security word shown in the picture. Click on the picture to hear an audio file of the word.
Click to hear an audio file of the anti-spam word