tomaugerdotcom
asked on
Actionscript 2.0 - waiting for a non-timeline event to complete
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();
iBox.flashImage();
iBox.zoomImage();
iBox.blurImage();
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!
Tom
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();
iBox.flashImage();
iBox.zoomImage();
iBox.blurImage();
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!
Tom
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
ASKER
I resolved the issue by building my own toolset with a dispatcher method that read in an array of arrays. Each array was a "command" - essentially the name of a private method on the object, for example "blur" or "fade", and followed by the parameters for that method, and a delay value.
The dispatacher would then see if there already was an "action" in progress, in which case it would do thing, otherwise, it would shift the first command off the queue and execute it.
Each private "action" method had a completion state that triggered a cleanup event. Part of the responsibilities of that cleanup event was to check the dispatch queue and if there were other commands in the queue, it would then process the next one via the dispatcher.
The dispatcher was also responsible for handling the delay. If a delay parameter was provided and the last "command" was just completed, it would initiate a timer event for the duration provided by that action's delay parameter.
Hope this is useful to someone out there,
Tom