Actionscript 2.0 - waiting for a non-timeline event to complete

Posted on 2007-10-08
Last Modified: 2010-08-05
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!

Question by:tomaugerdotcom
    LVL 14

    Accepted Solution

    I suggest you use the fusekit, it does exactly what you want and more:
    Just take your time to learn it a bit, because it's definitely worth it.

    LVL 14

    Author Comment

    I'm not feeling the love for a third-party tool with its own complicated API as a solution, but since it's the only one I got, I'll grant trigger the points to close off the question.

    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,


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Free Trending Threat Insights Every Day

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Sometimes you know that one object has a specific child in it, but you can't find the child. This happened to me when I was trying to code some actionScript to make a toolbar work with its embedded buttons.  My partner had created the toolbar usi…
    While working over numerous projects I often had the requirement for doing a screen capture in AS3.0. Unfortunately I found no "ready made" solutions in google search that suited my requirements. But I did come across some great resources which help…
    In this tutorial viewers will learn how to create a basic shape tween animation in Flash including shape hints for smooth animation Open a new document in Flash: Draw a shape: Select another frame (how long you want the tween to be): Right click and…
    The goal of the tutorial is to teach the user what frame rate is, how to control it and what effect it has on the video.

    759 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    12 Experts available now in Live!

    Get 1:1 Help Now