【IT168 技术资讯】1.如何监听键盘事件?
代码说明:有两种类型的键盘事件:KeyboardEvent.KEY_DOWN 和 KeyboardEvent.KEY_UP
以上是监听的是回车事件
要是想监听组合键,例如:Ctrl+Enter 键,代码如下:
}
2.怎么控制RichTextEditor的控制栏?
利用showControlBar属性,控制RichTextEditor的控制栏,这样把整个控制栏都关闭了
要是想分别控制控制栏中各寄宿控件,可以参考如下代码:
this.textEditor.alignButtons.height=0;
this.textEditor.alignButtons.visible=false;
this.textEditor.bulletButton.height=0;
this.textEditor.bulletButton.visible=false;
this.textEditor.linkTextInput.height=0;
this.textEditor.linkTextInput.visible=false;
this.textEditor._RichTextEditor_VRule1.height=0;
this.textEditor._RichTextEditor_VRule1.visible=false;
this.textEditor._RichTextEditor_VRule2.height=0;
this.textEditor._RichTextEditor_VRule2.visible=false;
3.控件双击事件(DoubleClick Event)怎么没反应?
<mx:Button doubleClickEnabled="true" doubleClick="doubleClickHandler(event)" x="48" y="32" label="Button"/>
private function doubleClickHandler(evt:MouseEvent):void
{
Alert.show("doubleClick");
}
代码说明:
doubleClickEnabled属性:指定对象是否接收 doubleClick 事件。默认值为 false,这意味着在默认情况下,不接收 doubleClick 事件。如果将 doubleClickEnabled 属性设置为 true,实例在其范围内接收 doubleClick 事件
4.怎么在TextArea的光标位置插入字符?
<mx:TextArea id="textEditor" x="11" y="366" width="399"/>
private function insertString(insertStr:String):void
{
if (this.textEditor.selectionBeginIndex == this.textEditor.selectionEndIndex)
{
var startPart:String=this.textEditor.text.substring(0, this.textEditor.selectionBeginIndex);
var endPart:String=this.textEditor.text.substring(this.textEditor.selectionEndIndex, this.textEditor.text.length);
startPart+=insertStr;
startPart+=endPart;
this.textEditor.text=startPart;
}
else
{
this.textEditor.text=insertStr;
}
}
5.实现TextArea控件的滚动条始终保持在最下面?
代码说明:这段代码是为了实现TextArea控件的滚动条始终保持在最下面,以方便用户查看聊天信息
要是VBox控件需要实现类似效果,可以看如下代码:
private function updateCompleteHandler(evt:FlexEvent):void
{
this.vd.verticalScrollPosition=this.vd.maxVerticalScrollPosition;
}
private function VALUE_COMMITHandler(evt:FlexEvent):void{
txt_content.verticalScrollPosition = txt_content.maxVerticalScrollPosition;
}