R – Validator Components in Flex3 Air

actionscript-3airapache-flexflex3

How to use validator controls like Required validator, integer validator etc in Air application? I tried to use them but I got this error:

Component declarations are not allowed here. (Note: visual children must implement mx.core.IUIComponent)

i have imported the validator like this…

import mx.validators.Validator;

and used like this

<mx:TextArea id="txtQuestCaption" change="txtQuestCaption_change(event)"/>
<mx:Validator id="reqValidator" source="txtQuestCaption">
</mx:Validator>

But i got that above error..

how to use validator in air ?

Best Answer

It seems that this code is nested inside some container tag. Move the <mx:Validator/> tag out of the current position and place it directly within the root mxml tag. Non visual tags like Validator, Style etc should be added as the immediate children of the root mxml tag

<!-- wrong -->
<?xml version="1.0" encoding="utf-8"?>
<mx:Panel xmlns:mx="http://www.adobe.com/2006/mxml">
 <mx:Canvas>
  <mx:TextArea id="txtQuestCaption" change="txtQuestCaption_change(event)"/>
  <mx:Validator id="reqValidator" source="txtQuestCaption"/>
 </mx:Canvas>
</mx:Panel>

<!-- correct -->
<?xml version="1.0" encoding="utf-8"?>
<mx:Panel xmlns:mx="http://www.adobe.com/2006/mxml">
  <mx:Canvas>
    <mx:TextArea id="txtQuestCaption" change="txtQuestCaption_change(event)"/>
  </mx:Canvas>
  <mx:Validator id="reqValidator" source="txtQuestCaption"/>
</mx:Panel>
Related Topic