2013-02-20 50 views
1

我是新來的Adobe flex開發人員。現在我正在處理應用程序,並且在我的mxml表單中我必須放置2個字段。如何在flex中顯示錯誤消息

一個是單選按鈕(選項(是,否)),另一種是文本框(名稱),並要求是:

  • 當用戶選擇是,那麼應將name字段,否則啓用它應該被禁用。 驗證規則:

    1. 如果用戶選擇是,他不會輸入任何值(文本框爲空),那麼我們應該顯示錯誤消息"value is required"

    2. 如果用戶選擇不和文本提交具有一定價值,那麼首先他必須刪除textfiled中的內容,然後只選擇'no'

有人請幫助我,給我一些代碼sample.That將是對我很大的幫助。

回答

0

根據TitleWindow和我們的PopupManager創建一個自定義的mxml控件來顯示它。

2

把這個代碼在你MXML應用程序並運行..

<?xml version="1.0" encoding="utf-8"?> 
    <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 
      xmlns:s="library://ns.adobe.com/flex/spark" 
      xmlns:mx="library://ns.adobe.com/flex/mx" 
      width="567" height="206" minWidth="955" minHeight="600" initialize="application1_initializeHandler(event)"> 
<fx:Script> 
    <![CDATA[ 
     import mx.controls.Alert; 
     import mx.events.FlexEvent; 

     protected function application1_initializeHandler(event:FlexEvent):void 
     { 


     } 

     protected function rd1_clickHandler(event:MouseEvent):void 
     { 

      if(!t1.enabled) 
      { 
       t1.enabled=true; 
      } 
      else if(t1.text=="" && t1.enabled) 
      { 
       Alert.show("Value is required in text box"); 
      } 
      else 
       t1.enabled=true; 
     } 

     protected function rd2_clickHandler(event:MouseEvent):void 
     { 
      t1.text=null 
      t1.enabled =false; 

     } 

    ]]> 
</fx:Script> 
<fx:Declarations> 
    <!-- Place non-visual elements (e.g., services, value objects) here --> 
</fx:Declarations> 
<s:TextInput x="132" y="41" id="t1"/> 
    <s:RadioButton x="162" y="91" label="Yes" id="rd1" groupName="select"   click="rd1_clickHandler(event)"/> 
<s:RadioButton x="211" y="91" label="No" id="rd2" groupName="select" click="rd2_clickHandler(event)" /> 
<s:Label x="79" y="45" text="Name"/> 
    </s:Application>