Triggering effects when a container’s visibility is changed

by Peter deHaan on September 20, 2007

in Effects, Panel, Zoom

The following example shows you how you can trigger effects when the visible property changes on a Flex container or control by using the hideEffect and showEffect effects.

Full code after the jump.

View MXML

<?xml version="1.0" encoding="utf-8"?>
<!-- http://blog.flexexamples.com/2007/09/20/triggering-effects-when-a-containers-visibility-is-changed/ -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
        layout="vertical"
        verticalAlign="middle"
        backgroundColor="white">

    <mx:Zoom id="zoom" />

    <mx:ApplicationControlBar dock="true">
        <mx:Button label="hide"
                click="panel.visible = false;"
                enabled="{panel.visible}" />
        <mx:Button label="show"
                click="panel.visible = true;"
                enabled="{!panel.visible}" />
    </mx:ApplicationControlBar>

    <mx:Panel id="panel"
            title="title"
            status="status"
            showEffect="{zoom}"
            hideEffect="{zoom}"
            width="100%"
            height="100%">

        <mx:ControlBar>
            <mx:Label text="control bar" />
        </mx:ControlBar>
    </mx:Panel>

</mx:Application>

View source is enabled in the following example.

If you want to use a specific easing type (Back, Bounce, Elastic, etc), you can use the following snippet specify the easing function that will be applied to the animation:

<mx:Script>
    <![CDATA[
        import mx.effects.easing.Bounce;
    ]]>
</mx:Script>

<mx:Zoom id="zoom" easingFunction="Bounce.easeOut" />

View source is enabled in the following example.

{ 4 comments… read them below or add one }

1 Maycon February 4, 2008 at 5:31 am

Can i add a bounce effect on it?

Reply

2 peterd February 4, 2008 at 7:29 am

Maycon,

Yeah, I updated the entry above, but basically you can specify the easingFunction property in your <mx:Zoom /> tag (or whatever effect you’re using).

Peter

Reply

3 Kg May 30, 2009 at 2:53 pm

Does anyone know how to get rid of that little flicker on the showEffect, where the target shows up for a millisecond BEFORE the effect starts?

Reply

4 Atul Singh Parihar July 31, 2009 at 5:10 am

Really very usefully

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: