Search

 


Yeah, right!

Adobe Flex EventListener fails on effect sequence 3

Posted by Paul McConnon Fri, 06 Jul 2007 21:39:00 GMT

I recently came across a gotcha when adding an event listener to a Flex effects sequence whose child effects were duplicated.

I had defined an effects sequence and an effect…

e.g.
var spinSequence:Sequence;
var mover:Move = new Move(target);
mover.yBy = -762;
mover.easingFunction = Linear.easeNone;
mover.duration = 1000;
I then added the same effect to the effects sequence multiple times
spinSequence.addChild(mover);
spinSequence.addChild(mover);
spinSequence.addChild(mover);

I then added an event listener to the sequence to be called when the sequence completed…

spinSequence.addEventListener("effectEnd", setComplete);

The effects sequence worked as I expected, chaining the effect 3 times before completing. Unfortunately I found that event listener would only be fired sporadically. Sometimes it would work for a while and then fail. Sometimes ir would fail straight away. I was pulling my hair out for ages (and I don’t got much of that to pull) before I tried creating duplicate events. For testing I just cut and pasted my code, creating 3 seperate Move effects (mover, mover2 and mover3), a la…

var mover:Move = new Move(target);
mover.yBy = -762;
mover.easingFunction = Linear.easeNone;
mover.duration = 1000;
var mover2:Move = new Move(target);
mover2.yBy = -762;
mover2.easingFunction = Linear.easeNone;
mover2.duration = 1000;
var mover3:Move = new Move(target);
mover3.yBy = -762;
mover3.easingFunction = Linear.easeNone;
mover3.duration = 1000;

and added the (now distinct) events to the sequence…

spinSequence.addChild(mover);
spinSequence.addChild(mover2);
spinSequence.addChild(mover3);

Now when adding the event listener, the event fires all the time. I suspect that the issue is one of Garbage Collection, but I’m new to Flex so I could be well wrong.

Anyways, posted this just in case someone else is slowly going bald with the same problem.