Sequencing effects in Flex using the mx:Sequence tag

by Peter deHaan on September 19, 2007

in Effects, Fade, Pause, Sequence, SetPropertyAction, WipeRight

The following example shows how you can use the <mx:Sequence /> MXML tag in Flex to create combined effects which execute in order. This example shows how to fade a display object in, pause, and then fade a display object out. Also, the same thing but with a combination of Wipe effects.

Full code after the jump.

View MXML

<?xml version="1.0" encoding="utf-8"?>
<!-- http://blog.flexexamples.com/2007/09/19/sequencing-effects-in-flex-using-the-mxsequence-tag/ -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
        layout="vertical"
        verticalAlign="middle"
        backgroundColor="white">

    <mx:Script>
        <![CDATA[
            private function fade_click():void {
                fader.stop();
                fader.play([box]);
            }

            private function wipe_click():void {
                wiper.stop();
                wiper.play([box]);
            }
        ]]>
    </mx:Script>

    <mx:Sequence id="fader">
        <mx:Fade alphaFrom="0.0" alphaTo="1.0" />
        <mx:Pause duration="{slider.value}" />
        <mx:Fade alphaFrom="1.0" alphaTo="0.0" />
    </mx:Sequence>

    <mx:Sequence id="wiper">
        <mx:SetPropertyAction name="alpha" value="1.0" />
        <mx:WipeRight showTarget="true" />
        <mx:Pause duration="{slider.value}" />
        <mx:WipeRight showTarget="false" />
        <mx:SetPropertyAction name="alpha" value="0.0" />
    </mx:Sequence>

    <mx:ApplicationControlBar dock="true">
        <mx:Button label="fade box"
                click="fade_click();" />
        <mx:Button label="wipe box"
                click="wipe_click();" />

        <mx:Spacer width="100%" />

        <mx:Label text="effect pause ({slider.value} ms):" />
        <mx:HSlider id="slider"
                minimum="1000"
                maximum="3000"
                value="1500"
                labels="[1000,2000,3000]"
                liveDragging="true"
                showTrackHighlight="true"
                snapInterval="100"
                tickInterval="500"
                dataTipPrecision="0" />
    </mx:ApplicationControlBar>

    <mx:Box id="box"
            width="100%"
            height="100%"
            backgroundColor="haloSilver"
            alpha="0.0" />

</mx:Application>

View source is enabled in the following example.

{ 7 comments… read them below or add one }

1 Venkat from INDIA November 22, 2007 at 10:28 am

Hi,

HOw do I get to apply independent effects on multiple containers in seqenece??

Reply

2 RR January 9, 2008 at 10:45 am

This was exactly what I was looking for, thanks for sharing!

Reply

3 Allen April 23, 2008 at 6:59 pm

Hi,
Thank you for your tutil ,
but I don’t know how to create Sequence using actionscript,
can you teach me?

Reply

4 peterd April 23, 2008 at 8:43 pm
5 sesha July 21, 2008 at 1:23 am

ok it s good

Reply

6 Miltan March 23, 2009 at 12:39 am

That’s a good article indeed. A very simple and handy one, that any flexer can try to implement. Thanks for all your effort

Reply

7 Rikki April 15, 2009 at 4:40 pm

Good article but…
can’t find anywhere how to apply such effect sequence on 2 different objects with diffrent time scale.
For exemple:
When flash is loaded (T0), object #1 appears and has an effect during 10 seconds.
At T0+3sec Object #2 appears and has an effect (different from object #1) of 3 seconds.

I can’t figure out how to achieve this!
Thanks for any tips.
Cheers

Reply

Leave a Comment

Sorry, this blog is terrible at eating HTML comments.
If you're pasting any HTML/XML/MXML code, you need to convert your < characters to &lt; and your > characters to &gt; .

You can use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="">

Anti-Spam Protection by WP-SpamFree

Previous post:

Next post: