Flex:显示/隐藏使用HDividedBox划分的VBox



我有两个通过HDividedBox划分的VBox。是否可以通过双击HDividedBox来显示或隐藏其中一个VBox
我知道moveDivider()getDividerAt()方法的用法,但对于这类问题,是否有HDividedBox功能。

因此,我建议使用自定义组件,而不是HDividedBox;)。

专门为您设计的基于事件的组件,处理双击分频器(200ms-双击间隔):

<?xml version="1.0" encoding="utf-8"?>
<mx:HDividedBox xmlns:mx="http://www.adobe.com/2006/mxml" initialize="hdividedbox1_initializeHandler(event)">
    <mx:Metadata>
        [Event(name="dividerDoubleClick", type="mx.containers.DividerDblClickEvent")]
    </mx:Metadata>
    <mx:Script>
        <![CDATA[
            import mx.controls.Alert;
            import mx.events.DividerEvent;
            import mx.events.FlexEvent;
            private var _timer:Timer = new Timer(200,1);                        
            protected function hdividedbox1_initializeHandler(event:FlexEvent):void{
                this.addEventListener(DividerEvent.DIVIDER_PRESS, divider_press);
            }           
            protected function divider_press(event:DividerEvent):void{
                if(_timer.running){
                    event.preventDefault();
                    event.stopPropagation(); // not sure what of it use
                    dispatchEvent(new DividerDblClickEvent(DividerDblClickEvent.DOUBLE_CLICK, event.dividerIndex));
                }else{
                    _timer.start();
                }
            }           
        ]]>
    </mx:Script>
</mx:HDividedBox>

AND自定义事件

package mx.containers
{
    import flash.events.Event;
    public class DividerDblClickEvent extends Event{
        // Define static constant.
        public static const DOUBLE_CLICK:String = "dividerDoubleClick";
        public var dividerIndex:int = -1; // not set
        public function DividerDblClickEvent(type:String, dividerIndex:int = -1, bubbles:Boolean=false, cancelable:Boolean=false){
            super(type, bubbles, cancelable);// Call the constructor of the superclass.
            this.dividerIndex = dividerIndex;// Set the new property.
        }
        // Override the inherited clone() method.
        override public function clone():Event {
            return new DividerDblClickEvent(type, dividerIndex);
        }
    }
}

使用示例:

    <?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" xmlns:local="*" xmlns:c="mx.containers.*">
    <mx:Script>
        <![CDATA[
            import mx.effects.easing.Cubic;
        ]]>
    </mx:Script>
    <mx:AnimateProperty id="hide" easingFunction="{Cubic.easeIn}" target="{to_hide}" property="width" toValue="0" duration="700" />
<c:HDividedBoxD height="100%" width="100%" dividerDoubleClick="hide.play();" >
    <mx:VBox height="100%" width="50%" backgroundColor="#00FF00">
        <mx:Label text=" some text left 1"/>
        <mx:Label text=" some text left 2"/>
    </mx:VBox>
    <mx:VBox id="to_hide" height="100%" width="50%" backgroundColor="#0000FF">
        <mx:Label text=" some text right 3"/>
        <mx:Label text=" some text right 4"/>       
    </mx:VBox>      
</c:HDividedBoxD>       
</mx:Application>

您可以根据需要修改该模块。我只想感谢:)

最新更新