I’m having trouble properly removing an eventListener that keeps looping.
Here’s my code:
var speed:Number = 1.1;
button.addEventListener(MouseEvent.CLICK, splitBox);
function splitBox(evt:MouseEvent):void {
button.addEventListener(Event.ENTER_FRAME, ease);
}
function ease(evt:Event):void {
Box1_mc.x = 140 - (140 - Box1_mc.x) / speed;
Box2_mc.x = 400 - (400 - Box2_mc.x) / speed;
[COLOR=Red]if ([COLOR=RoyalBlue]Box1_mc has reached its x-coordinate destination[/COLOR]) {
[COLOR=RoyalBlue]Box1_mc.x = it's final x-coordinate destination[/COLOR]
[COLOR=RoyalBlue]button.removeEventListener(Event.ENTER_FRAME, ease);[/COLOR]
//stop running the 'ease' function
}[/COLOR]
trace(Box1_mc.x); [COLOR=Red]//when I trace I get
an infinate number loop of 140 eventually, the
coordinate where it's supposed to stop[/COLOR]
}
button.buttonMode = true;
This would basically end the loop, and rest Box1_mc after easing into position. I would then apply the same concept to Box2_mc. I’m still a beginner, a simple explanation and help would be great.