Flex開發過程中常見問題解答
本文和大家重點討論一下Flex組件開發總結,在平時的Flex開發過程中遇到的問題以及解決辦法總結如下,希望本文的介紹能讓你有所收獲。
Flex組件開發總結
在平時的Flex開發過程中遇到的問題以及解決辦法總結如下:
1.Flex開發過程中如何監聽鍵盤事件?
代碼說明:有兩種類型的鍵盤事件:KeyboardEvent.KEY_DOWN和KeyboardEvent.KEY_UP
以上是監聽的是回車事件
要是想監聽組合鍵,例如:Ctrl+Enter鍵,代碼如下:
- if(evt.keyCode==13&&evt.ctrlKey){
- }
2.Flex開發過程中怎么控制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.Flex開發過程中控件雙擊事件(DoubleClickEvent)怎么沒反應?
- <mx:ButtondoubleClickEnabledmx:ButtondoubleClickEnabled="true"doubleClick="doubleClickHandler(event)"x="48"y="32"label="Button"/>
- privatefunctiondoubleClickHandler(evt:MouseEvent):void
- {
- Alert.show("doubleClick");
- }
代碼說明:
doubleClickEnabled屬性:指定對象是否接收doubleClick事件。默認值為false,這意味著在默認情況下,不接收doubleClick事件。如果將doubleClickEnabled屬性設置為true,實例在其范圍內接收doubleClick事件
4.Flex開發過程中怎么在TextArea的光標位置插入字符?
- <mx:TextAreaidmx:TextAreaid="textEditor"x="11"y="366"width="399"/>
- privatefunctioninsertString(insertStr:String):void
- {
- if(this.textEditor.selectionBeginIndex==this.textEditor.
- selectionEndIndex)
- {
- varstartPart:String=this.textEditor.text.substring(0,this.textEditor.selectionBeginIndex);
- varendPart: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.Flex開發過程中實現TextArea控件的滾動條始終保持在最下面?
代碼說明:這段代碼是為了實現TextArea控件的滾動條始終保持在最下面,以方便用戶查看聊天信息
要是VBox控件需要實現類似效果,可以看如下代碼:
- <mx:VBoxidmx:VBoxid="vd"updateComplete="updateCompleteHandler(event)"x="10"y="10"width="399"height="348">
- privatefunctionupdateCompleteHandler(evt:FlexEvent):void
- {
- thisthis.vd.verticalScrollPosition=this.vd.
- maxVerticalScrollPosition;
- }
- this.txt_content.addEventListener(FlexEvent.VALUE_COMMIT,VALUE_COMMITHandler);
- privatefunctionVALUE_COMMITHandler(evt:FlexEvent):void{
- txt_contenttxt_content.verticalScrollPosition=txt_content.
- maxVerticalScrollPosition;
- }
【編輯推薦】
- 解析如何使用Flex開發DataGrid分頁控件
- FlexBuilder4十大新特性閃亮登場
- Flex開發者需要知道的哪點事
- 經驗總結 Flex開發時需要注意的幾個問題
- 技術分享 在Flex中嵌入Flex字體的步驟