我已经按照this教程在TextInput上实现了IP验证器。但是,我几个小时都无法解决跟踪错误。
错误:
Could not resolve <flexScript:IPAddressValidator> to a component implementation. MasterTabNavigator.mxml /XflowGUI/src/view
代码:
MasterTabNavigator.mxml:
<mx:TabNavigator xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
xmlns:flexScript="flexScript.*" >
<s:TextInput id="txtServerIP" width="200"/>
<flexScript:IPAddressValidator source="{txtServerIP}" property="text"/>
</mx:TabNavigator>
flexScript包:(给出here
的代码的精确副本package flexScript
{
import mx.validators.ValidationResult;
import mx.validators.Validator;
public class IPAddressValidator extends Validator {
public function IPAddressValidator() {
// Call base class constructor.
super();
}
override protected function doValidation(value:Object):Array {
// create an array to return.
var ValidatorResults:Array = new Array();
// Call base class doValidation().
ValidatorResults = super.doValidation(value);
// Return if there are errors.
if (ValidatorResults.length > 0)
return ValidatorResults;
if (String(value).length == 0)
return ValidatorResults;
var RegPattern:RegExp = /\b(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\b/;
var a:Array = RegPattern.exec(String(value));
if (a == null)
{
ValidatorResults.push(new ValidationResult(true, null, "IPAddress Error","You must enter an IP Address"));
return ValidatorResults;
}
return ValidatorResults;
}
}
}
如果有人能发现我犯的错误,我会很高兴的。另外,我没有两个与this帖子中提到的相同的组件,其中查询者有一个非常相似的问题。
答案 0 :(得分:0)
您是否尝试将IPAddressValidator置于flex:声明部分......?应该在那里。
答案 1 :(得分:0)
找到了修复方法。我运行了你的代码,和你一样的问题,所以将flexScript
软件包名称更改为flexScript1
(必须是某种保留字),并将IPValidator添加到声明标记中,它完美无缺。需要两个变化才能发挥作用。
<fx:Declarations>
<flexscript1:IPAddressValidator source="{txtServerIP}" property="text"/>
</fx:Declarations>
以下是为Flex 4.5 Web应用程序运行的完整代码:
<?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" minWidth="955" minHeight="600"
xmlns:flexscript1="flexscript1.*">
<s:layout>
<s:VerticalLayout/>
</s:layout>
<fx:Declarations>
<!-- Define the PhoneNumberValidator. -->
<flexscript1:IPAddressValidator id="pnV"
source="{phoneInput}" property="text"
/>
</fx:Declarations>
<s:TextInput id="phoneInput" keyUp="{phoneInput}"/>
<s:TextInput id="focusOut"/>
</s:Application>
另外,在键入时,请查看以下用于验证的链接: Flex - number validation, wont remove red glow if click focus? (example provided)