簡體   English   中英

當輸入文本數據隨着動作2更改時,如何顯示警報?

[英]how to show Alert while the input text data is changing with actionscript 2?

我想使用FLASH ActionScript 2進行輸入文本驗證。輸入文本僅顯示大於5的數字,因此,如果我嘗試輸入數字0、1、2、3、4,則警報將彈出並提供以下信息:數據應高於5。

我想在輸入文本更改時進行驗證處理,因為我不使用任何按鈕作為觸發器。

import mx.controls.Alert;

var tiListener:Object = new Object();

tiListener.change = function(evt_obj:Object)
{
   if(inputText.text < 5)
   {
      trace("Numbers below 5 are not allowed");
      Alert.show("Numbers below 5 are not allowed", "Error");
      inputText.setFocus(); 
   };
};

proj.addEventListener("change", tiListener);

跟蹤輸出運行良好,但未顯示警報。 任何身體有什么解決辦法? 謝謝..

inputText文本的類型為string ,並且您希望它為number 使用parseInt方法將您的字符串轉換為integer

inputText.onChanged = function(tf:TextField) 
{
    if (parseInt(tf.text) < 5)
   {
      trace("Numbers below 5 are not allowed");
      Alert.show("Numbers below 5 are not allowed", "Error");
      inputText.setFocus();
   }
}

將此代碼放入您的函數中,這將更加清楚:

trace(typeof(tf.text));
trace(typeof(parseInt(tf.text)));

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM