Actionscript 2.0 - waiting for a non-timeline event to complete
Posted on 2007-10-08
Hi there! I'm working with a custom class called ImageBox. I'm using it to create a sort of image viewer. There will be multiple instances of these ImageBox objects on stage, and I want to be able to control their behaviour through actionscript.
I am creating a number of methods on ImageBox that do various visual effects. For example, I have a method that will cause the image to flash to white, another will blur the image, another will scale the image to full screen size, and so forth. I'm making extensive use of the Tween class to do these effects, rather than the timeline.
Now I'm looking for an elegant way to string all these actions together in sequence. Once I've imported the class into my main flash movie, I want to be able to do the following in a timeline script:
my iBox = new ImageBox();
The intended result being that the image flashes, then zooms, then blurs.
Of course, right now, all three effects will happen more-or-less simultaneously.
What's an elegant way of making each effect wait until the previous one has completed before starting? I'm thinking every time you call an effect method on an ImageBox object, that method goes into a queue. The first one processes, then when it's complete, the next one kicks in.
I anticipate that for all Tween-based effects, you would make use of an onMotionComplete() callback.
It would also be nice to be able to build in a delay between subsequent "effects".
Anyone seen this before or want to take a crack at it? I'm sure I can do it, but before I start, I'd love to get another expert's Best Practice. How would you manage the queue? How would you make the system as flexible as possible and the interface as elegant as possible?
Thanks for your insights and creativity!