How can I turn off event listeners in other classes?
To save anyone reverse engineering my reams of code, here it is in a nutshell.
Two buttons, left and right, move the (full screen) backgrounds. If you click the right arrow, the current background moves left, the new background is added to the right, is also moved left, and the old background is faded out. Think of it as a long stream of backgrounds, being moved back and forth with the previously viewed one being faded out with a tween.
The problem is that the arrows appear too soon, and clicking one breaks the whole thing.
Main.as adds the arrows & adds the event listeners which then call the functions. The Main.as functions to move the backgrounds use background.moveLeft(); in the backgrounds class, which is where the fade out tweens happen.
So - how do I turn OFF the buttons (added in Main.as) when the tween (in background.as) has finished? I've tried using something like " getNextRoom.addEventListener(TweenEvent.MOTION_FIN ISH, turnOff);" with turnOff referencing the arrows, but it complains that they don't exist (and in the backgrounds class they don't).
Thanks!
Rooms.as (used for the rooms, or backgrounds)
Actionscript Code:
package
{
import flash.display.MovieClip;
import flash.events.Event;
import flash.events.MouseEvent;
import fl.transitions.Tween;
import fl.transitions.TweenEvent;
import fl.transitions.easing.*;
import flash.filters.BlurFilter;
public class rooms extends MovieClip
{
public function rooms()
{
//hideNotes();
}
//Room Navigation
public function moveLeft(New:Boolean):void
{
trace(this +' moving left, New Room? ' + New );
if (New == true)
{ this.alpha = 1;
var getNewRoom:Tween = new Tween(this,"x",Strong.easeOut,2880,0,2,true);
getNewRoom.addEventListener(TweenEvent.MOTION_FINISH, listenAgain);
}
else if (New == false)
{
var moveOldRoom:Tween = new Tween(this,"x",Strong.easeOut,0,-2880,2,true);
moveOldRoom.addEventListener(TweenEvent.MOTION_FINISH, turnOffLights);
}
}
public function moveRight(New:Boolean):void
{
trace(this +' moving right New Room? ' + New );
if (New == true)
{ this.alpha = 1;
var getNextRoom:Tween = new Tween(this,"x",Strong.easeOut,-2880,0,2,true);
getNextRoom.addEventListener(TweenEvent.MOTION_FINISH, listenAgain);
}
else if (New == false)
{
var movePrevRoom:Tween = new Tween(this,"x",Strong.easeOut,0,2880,2,true);
movePrevRoom.addEventListener(TweenEvent.MOTION_FINISH, turnOffLights);
}
}
public function listenAgain(event:TweenEvent):void
{
trace('yay, listening again.');
}
public function turnOffLights(event:TweenEvent):void
{
var fadeThisRoom:Tween = new Tween(this,"alpha",Strong.easeOut,1, 0, 1,true);
fadeThisRoom.addEventListener(TweenEvent.MOTION_FINISH, removeRoom);
}
public function removeRoom(event:TweenEvent):void
{
//removeChild(this);
}
}
}