The following example shows how you can fade in a Spark DropDownList pop up menu in Flex Gumbo by creating a custom DropDownList skin and setting the transitions property to a transition Fade effect.

Full code after the jump.

To use the following code, you must have Flash Player 10 and a Flex Gumbo SDK installed in your Flex Builder 3. For more information on downloading and installing the Gumbo SDK into Flex Builder 3, see “Using the beta Gumbo SDK in Flex Builder 3″.

View MXML

<?xml version="1.0" encoding="utf-8"?>
<!-- http://blog.flexexamples.com/2009/04/28/setting-a-fade-transition-on-a-spark-dropdownlist-component-in-flex-gumbo/ -->
<s:Application name="Spark_DropDownList_transitions_test"
        xmlns:fx="http://ns.adobe.com/mxml/2009"
        xmlns:s="library://ns.adobe.com/flex/spark"
        xmlns:mx="library://ns.adobe.com/flex/halo">

    <fx:Declarations>
        <s:ArrayList id="arrList"
                source="[Red,Orange,Yellow,Green,Blue]" />
    </fx:Declarations>

    <s:DropDownList id="dropDownList"
            dataProvider="{arrList}"
            requiresSelection="true"
            skinClass="skins.CustomDropDownListSkin"
            horizontalCenter="0"
            top="20" />

</s:Application>

The custom Spark DropDownList skin, CustomDropDownListSkin.mxml, is as follows:

View skins/CustomDropDownListSkin.mxml

<?xml version="1.0" encoding="utf-8"?>
<!-- http://blog.flexexamples.com/2009/04/28/setting-a-fade-transition-on-a-spark-dropdownlist-component-in-flex-gumbo/ -->
<s:SparkSkin name="CustomDropDownListSkin"
        xmlns:fx="http://ns.adobe.com/mxml/2009"
        xmlns:s="library://ns.adobe.com/flex/spark"
        alpha.disabled="0.5">
    <s:states>
        <s:State name="normal" />
        <s:State name="open" />
        <s:State name="disabled" />
    </s:states>
    <s:transitions>
        <s:Transition fromState="normal" toState="open">
            <s:Fade target="{popup}" duration="3000" />
        </s:Transition>
    </s:transitions>

    <!-- host component -->
    <fx:Metadata>
        <![CDATA[
            [HostComponent("spark.components.DropDownList")]
        ]]>
    </fx:Metadata>

    <!--- Defines the appearance of the DropDownList component's drop down area. -->
    <s:PopUp id="popup"
            open.normal="false" open.open="true"
            includeIn="open"
            left="0" right="0" top="0" bottom="0"
            visible.open="true" visible.normal="false"
            placement="below">
        <s:Group id="dropDown"
                maxHeight="134" minHeight="22"
                visible.open="true" visible.normal="false">
            <!-- border -->
            <s:Rect left="0" right="0" top="0" bottom="0">
                <s:stroke>
                    <s:SolidColorStroke color="0x686868" weight="1"/>
                </s:stroke>
            </s:Rect>

            <!--- fill --->
            <s:Rect id="background" left="1" right="1" top="1" bottom="1" >
                <s:fill>
                    <s:SolidColor id="bgFill" color="0xFFFFFF" />
                </s:fill>
            </s:Rect>

            <s:Scroller left="1" top="1" right="1" bottom="1" >
                <s:DataGroup id="dataGroup" itemRenderer="spark.skins.default.DefaultItemRenderer">
                    <s:layout>
                        <s:VerticalLayout gap="0" horizontalAlign="contentJustify"/>
                    </s:layout>
                </s:DataGroup>
            </s:Scroller>

            <s:filters>
                <s:DropShadowFilter blurX="20" blurY="20" distance="5" angle="90" alpha="0.6" />
            </s:filters>
        </s:Group>
    </s:PopUp>

    <s:Button id="button" left="0" right="0" top="0" bottom="0" focusEnabled="false"
        skinClass="spark.skins.default.DropDownListButtonSkin" />
    <s:SimpleText id="labelElement" verticalAlign="middle"
        left="7" right="30" top="2" bottom="2" verticalCenter="1" />

</s:SparkSkin>

View source is enabled in the following example.

This entry is based on a beta version of the Flex Gumbo SDK and therefore is very likely to change as development of the Flex SDK continues. The API can (and will) change causing examples to possibly not compile in newer versions of the Flex Gumbo SDK.

 
Tagged with:
 
About The Author

Peter deHaan

Peter deHaan currently works for Adobe on the Flex SDK QA team. While not working on Flex, Flash, and ColdFusion applications, Peter enjoys making up bios and writing in 3rd person. Peter's rarely updated blog can be found at blogs.adobe.com/pdehaan/, actionscriptexamples.com, airexamples.com, and coldfusionexamples.com.

7 Responses to Setting a fade transition on a Spark DropDownList component in Flex Gumbo

  1. Ian Ilsley says:

    Nice , how about a ‘sliding’ effect , so the ‘PopUp’ ‘slides’ in from the bottom of the button ?

  2. beshan says:

    <s:transitions>
    <s:Transition fromState=”normal” toState=”open”>
    <s:Wipe target=”{popUp.popUp}” duration=”200″ direction=”down” />
    </s:Transition>
    <s:Transition fromState=”open” toState=”normal”>
    <s:Wipe target=”{popUp.popUp}” duration=”200″ direction=”up” />
    </s:Transition>
    </s:transitions>

    <s:PopUpAnchor id=”popUp” left=”0″ right=”0″ top=”0″ bottom=”0″
    popUpPosition=”below” popUpWidthMatchesAnchorWidth=”true” includeIn=”open”
    displayPopUp.normal=”false” displayPopUp.open=”true”>

  3. Deepak says:

    I added only this piece of code in the custom skin:

    But it works only for the first time! Rest of the times, it behaves normally with no effects. Any idea what else needs to be done? If I use only “popUp” as target, no effects are working.

  4. Deepak says:

    I added only this piece of code in the custom skin:

  5. Starburst says:

    Thanks beshan! Works perfectly!

  6. Monmas says:

    THANK YOU!!! beshan! your codes saved me……

  7. Scott Talsma says:

    Deepak–In order to get the transition to fire more than once, you need to change the destruction policy on the PopupAnchor (itemDestructionPolicy=”never”):


    <!---
    The PopUpAnchor control that opens the drop-down list.

    In a custom skin class that uses transitions, set the
    itemDestructionPolicy property to never.
    -->

Leave a Reply

Your email address will not be published.

You may 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