我有两个 VBoxes 通过 HDdividedBox 划分。是否可以通过双击 HDvidedBox 来显示或隐藏其中一个 VBox?
我知道moveDivider()
andgetDividerAt()
方法的使用,但是对于这类问题是否有任何 HDividedBox 功能。
问问题
862 次
1 回答
2
所以,我建议使用自定义组件而不是 HDIVvidedBox ;)。
特别适合您 - 基于事件的组件,它处理双击分隔线(200ms - doubleClick 间隔):
<?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>
和自定义事件
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>
您可以根据需要修改该模块。我只想谢谢:)
于 2012-07-19T14:20:12.573 回答