创建了两个textfield,我必须对其进行验证,并在警报框中显示错误消息。在4.5中不支持mx.controls.Alert。我尝试从源路径中包含mx。请帮助我通过验证textfield是否为空来显示警报框。
<code>
<?xml version="1.0" encoding="utf-8"?>
<s:View xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark" title="validation">
<fx:Declarations>
<fx:Component className="AlertMsg">
<s:SkinnablePopUpContainer x="70" y="100">
<s:TitleWindow title="My Message" close="close()">
<s:VGroup horizontalAlign="center" paddingTop="8" paddingBottom="8" paddingLeft="8" paddingRight="8" gap="5" width="100%">
<s:Label text="My alert message text here..."/>
<s:Button label="OK" click="close()"/>
</s:VGroup>
</s:TitleWindow>
</s:SkinnablePopUpContainer>
</fx:Component>
</fx:Declarations>
<s:layout>
<s:VerticalLayout paddingTop="5" paddingBottom="5" paddingLeft="5" paddingRight="5" gap="10"
horizontalAlign="center" verticalAlign="top"/>
</s:layout>
<s:TextInput id="firstName"/>
<s:TextInput id="zipCodeInput"/>
<s:Button label="Show Alert" click="(new AlertMsg()).open(this, false)"/>
</s:View>
</code>这里的警报显示在fx:声明中。如何通过验证textfield来显示警报消息。请帮帮忙
发布于 2013-09-01 01:50:43
在“显示警报”按钮上添加一个单击处理程序,而不是直接显示警报框。然后,验证TextInput字段的值。如果它是空的,显示你的警觉。
<fx:Script>
<![CDATA[
private function validateField() : void {
if (firstName.text == "" || zipCodeInput.text == "")
new AlertMsg().open(this, false);
}
]]>
</fx:Script>
<s:Button label="Show Alert" click="validateField()"/>https://stackoverflow.com/questions/18547624
复制相似问题