Himanshu Yadav
Himanshu Yadav

Reputation: 13585

Flex: Show/Hide VBoxes divided using HDividedBox

I have two VBoxes divided via a HDividedBox. Is it possible to show or hide one of the VBox by double clicking on HDividedBox?
I know the use of moveDivider() and getDividerAt() methods but is there any HDividedBox functionality for this kind of problem.

Upvotes: 0

Views: 865

Answers (1)

MaxXx1313
MaxXx1313

Reputation: 620

So, i recommend to use custom component instead of HDividedBox ;).

Specially for you - event-based component, which process double-click on divider (200ms - doubleClick interval):

<?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 custom event

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);
        }
    }
}

Example of using:

    <?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>

You can modify that module as you want. I want just thanks:)

Upvotes: 2

Related Questions