Flash
import fl.transitions.Tween;
import fl.transitions.easing.*;
import flash.utils.Timer;
import flash.events.TimerEvent;
importflash.display.MovieClip;
import flash.events.MouseEvent;
import fl.transitions.TweenEvent;
// declaro variables iniciales
var tiempo_ti:Timer = new Timer(1000,60);
var puntos:Number = 0;
// inicio eljuego
tiempo_ti.start();
tiempo_ti.addEventListener(TimerEvent.TIMER,agregarBola);
tiempo_ti.addEventListener(TimerEvent.TIMER_COMPLETE,finalizar);
function agregarBola(e:TimerEvent)
{
//creouna nueva bola desde el objeto que hay en la libraria
var bola_mc:MovieClip=new Bola ();
// ubico la bola en x calculando un numero al azar
bola_mc.x = Math.random() * 800;
//dentro de la bola creo una animacion
bola_mc.animar = new Tween(bola_mc,"y",Bounce.easeOut,0,575,5,true);
// creo una escucha cuando se acabe la animacion bola_mc.animar.addEventListener(TweenEvent.MOTION_FINISH,restarPuntos);
// creo una escucha para cuando se le da click a la bola ;
bola_mc.addEventListener(MouseEvent.CLICK, sumarPuntos);
//adjunto la bola al escenario ;addChild(bola_mc);
}
function sumarPuntos(e:MouseEvent)
{
//remuevo el objeto al que se la hace click, necesito decirle que trate como si fuera un movieclip al objeto al que se le hizoclick(casting)
removeChild(MovieClip(e.target));
puntos++;
//hago un casting de la variable para poder moestrarla en el texto de la caja
puntos_txt.text = String(puntos);
// le decimos a laanimacion del objeto al que se le hizo click que se de tegenga
e.target.animar.stop();
}
function restarPuntos(e:TweenEvent)
{
// resta puntaje 1 a 1
puntos--;
puntos_txt.text =String(puntos);
// removemos la escucha del objeto que le estamos aplicando la animacion
e.target.obj.removeEventListener(MouseEvent.CLICK, sumarPuntos);
}
function finalizar(e:TimerEvent)
{...
Regístrate para leer el documento completo.