Friday, April 13, 2007

Multiple "effectEnd" events from a parallel effect

I created a parallel effect with AS3...

var zoom:Zoom = new Zoom();
zoom.easingFunction = Exponential.easeIn;
zoom.duration = 1500;
zoom.zoomHeightFrom = 0.0;
zoom.zoomHeightTo = 1.0;

var fade:Fade = new Fade();
fade.easingFunction = Exponential.easeIn;
fade.alphaFrom = 0;
fade.alphaTo = 1;
fade.duration = 1500;

msgEffect = new Parallel();
msgEffect.targets = effectsArray;
msgEffect.addChild(zoom);
msgEffect.addChild(fade);
msgEffect.play();
I added a listener for when the effect ends...

addEventListener(EffectEvent.EFFECT_END, close);
Then I coded the following handler...

private function close(event:EffectEvent=null):void
{
visible = false;
mx.managers.PopUpManager.removePopUp(this);
dispatchEvent(closeEvent);
}
Even though the effects are part of a parallel effect sequence object, two "effectEnd" events are fired one for the Zoom and the other for the Fade.

I believe this occurs because the targets fire the "effectEnd" event, not the parallel effect sequence object.

It looks like I need some wrapper that says, "Hey, both effects in your parallel effect sequence object are done!" Seems odd though, shouldn't the parallel sequence object do that?

Well, here's my very cheesy fix for this problem. I changed the event handler as follows...

private function close(event:EffectEvent=null):void
{
  visible = false;
  mx.managers.PopUpManager.removePopUp(this);
  dispatchEvent(closeEvent);
  // Ignore any other "effectEnd" events.
  removeEventListener(EffectEvent.EFFECT_END, close);
}

1 comment:

Unknown said...

the example is very unclear.
what is effectsArray ?
when do you create the popUp ?
where is this code written ? in a window ? in a titledWindow ? in a canvas ??

very unclear example