En mi ejemplo tengo un .fla con 3 frames, y en cada frame hay un boton al que le he asignado una funcion cuya unica finalidad es avanzar al siguiente frame, o al primero, si el frame en que se encuentra es el ultimo.
Este es el codigo:
Código :
stop();
fActualizar();
function fActualizar():void {
var tTimer:Timer = new Timer(100, 1);
tTimer.addEventListener(TimerEvent.TIMER, fVerBoton);
tTimer.start();
}
function fVerBoton(event:TimerEvent):void {
for (var i:uint = 0; i < numChildren; i++) {
if (getChildAt(i) is Button) {
var btnDeMarras:Button = getChildAt(i) as Button;
}
}
btnDeMarras.addEventListener(MouseEvent.CLICK, fNextFrame);
}
function fNextFrame(event:MouseEvent):void {
if (currentFrame < totalFrames) {
nextFrame();
} else {
gotoAndStop(1);
}
fActualizar();
}
Lo de la funcion fActualizar es porque Flash tarda un tiempo en "ver" lo que hay en el nuevo frame, y antes de que esto ocurre es imposible asignar listeners ni nada a los objetos que en el se encuentren.
Bueno este script "funciona", pero tiene un problema; y es que si se hace click demasiado rapido en los botones, termina dando este error:
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at NAVEGADESDEFLA_fla::MainTimeline/fVerBoton()
at flash.utils::Timer/_timerDispatch()
at flash.utils::Timer/tick()
He probado variando el tiempo del Timer pero nada, y me pregunto si habria alguna forma de evitar este error.
Gracias.

Zguillez