This is a spark skin for a simple ComboBox but to make the content of the drop down slide down when you open the combo there\'s a few hoops you need to jump through.\r\n\r\nUsually the PopUpAnchor object has an includeIn property set to the \'open\' state of the skin. This means the content transition needs to be set for it to have any effect when it appears. You can use a simple fade or scale but most people want to see the pop-up \'drop down\' maybe with a slide and some easing. To do this you need to use the Move effect and animate the position of the content as it moves into place.\r\n\r\nThis effect happens by making sure the content is within a group that has its clipAndEnableScrolling property set to true so the content is masked. Now that should be as straightforward as it gets BUT there\'s a problem.\r\n\r\nWhen the \'open\' state is first initiated the popup content is instantiated and takes a few ticks to be created and have its height measured so we can use this number in our Move effect.\r\n\r\nSo we need to listen for the state change and detect if the content is created before starting the effect. If it isn\'t we need to listen to the creationComplete handler to determine the height and then run the effect.\r\n\r\nThis is a simple hack that assumes you\'re not going to change the height of the Scroller object on the fly. If this were the case you\'d probably have to adjust the popupHeight property using the commitProperties handler of the scroller instead.
<?xml version="1.0" encoding="utf-8"?> <!-- ADOBE SYSTEMS INCORPORATED Copyright 2008 Adobe Systems Incorporated All Rights Reserved. NOTICE: Adobe permits you to use, modify, and distribute this file in accordance with the terms of the license agreement accompanying it. --> <!--- The default skin class for the Spark ComboBox component. The skin for the anchor button for a ComboBox component is defined by the ComboBoxButtonSkin class. The skin for the text input is defined by the ComboBoxTextInputSkin class. @see spark.components.ComboBox @see spark.skins.spark.ComboBoxButtonSkin @langversion 3.0 @playerversion Flash 10 @playerversion AIR 1.5 @productversion Flex 4 --> <s:SparkSkin xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark" xmlns:fb="http://ns.adobe.com/flashbuilder/2009" alpha.disabled=".5" > <!-- host component --> <fx:Metadata> <![CDATA[ /** * @copy spark.skins.spark.ApplicationSkin#hostComponent */ [HostComponent("spark.components.ComboBox")] ]]> </fx:Metadata> <fx:Script> <![CDATA[ import mx.events.FlexEvent; import mx.events.StateChangeEvent; [Bindable] protected var popupStartPosition:Number; [Bindable] protected var popupHeight:Number; protected var isDataGroupCreated:Boolean; //---------------------------------------------------------------------------- static private const exclusions:Array = ["popUp"]; /** * @private */ override public function get colorizeExclusions():Array {return exclusions;} //---------------------------------------------------------------------------- override protected function initializationComplete():void { useChromeColor = true; super.initializationComplete(); } //---------------------------------------------------------------------------- protected function stateChangeHandler(event:StateChangeEvent):void { if(event.newState == "open") { popUp.displayPopUp = true; if(scroller && isDataGroupCreated) openPop.play(); } else if(scroller && event.newState == "normal" && isDataGroupCreated) { closePop.play(); } } //----------------------------------------------------------------------------- protected function dataGroup_creationCompleteHandler(event:FlexEvent):void { popupStartPosition = scroller.y; popupHeight = scroller.height; isDataGroupCreated = true; if(currentState == "open") openPop.play(); } ]]> </fx:Script> <s:states> <s:State name="normal" /> <s:State name="open" /> <s:State name="disabled" /> </s:states> <fx:Declarations> <s:Power id="powerEaser" /> <s:Move id="openPop" target="{scroller}" easer="{powerEaser}" duration="300" yFrom="{popupStartPosition-popupHeight}" yTo="{popupStartPosition}" /> <s:Move id="closePop" target="{scroller}" easer="{powerEaser}" duration="300" effectEnd="{popUp.displayPopUp = false}" yFrom="{popupStartPosition}" yTo="{popupStartPosition-popupHeight}" /> </fx:Declarations> <s:PopUpAnchor id="popUp" displayPopUp.normal="false" displayPopUp.open="true" left="0" right="0" top="0" bottom="0" popUpPosition="below" popUpWidthMatchesAnchorWidth="true" > <s:Group id="dropDown" clipAndEnableScrolling="true" > <s:Scroller id="scroller" left="0" top="0" right="0" bottom="0" hasFocusableChildren="false" > <s:DataGroup id="dataGroup" itemRenderer="skins.list.SC_ListItemRenderer" > <s:layout> <s:VerticalLayout gap="0" horizontalAlign="contentJustify"/> </s:layout> </s:DataGroup> </s:Scroller> </s:Group> </s:PopUpAnchor> <s:Button id="openButton" width="20" height="20" right="0" top="0" bottom="0" focusEnabled="false" skinClass="skins.comboBox.SC_ComboBoxButtonSkin" /> <s:TextInput id="textInput" text="Choose ..." height="20" left="0" right="20" top="0" bottom="0" focusEnabled="false" skinClass="skins.comboBox.SC_ComboBoxTextInput" /> </s:SparkSkin>
You need to login to post a comment.
