R – Flex: Databinding watch

actionscriptactionscript-3apache-flexdata-bindingflash

Given this MXML component:

<mx:TextBox id="test" text="{test2.text.length &gt; 5}" />

How can I get an event dispatched whenever the value of test2.text.length > 5 changes? I've tried ChangeWatcher, BindUtils and PropertyChangeEvent, but no luck 🙁

Thanks;

[EDIT]

Copying my comments from further down:

Well… I'm actually using a new bindable field, in my own TextField component, called validationResult. I'm trying to do atomic validations instead of the whole lot. Anyway. the test2.text.length > 5 condition is defined per instance so I can't hardcode it like that.

Example MXML:

<nui:NewTextInput id="mensualDeclarado2" validationResult="{mensualDeclarado3.text.length >= 5 && mensualDeclarado3.text.length <= 10)}" />

<nui:NewTextInput id="mensualDeclarado3" text="1234567890" />

Best Solution

Why not through a new event within the change event of test2?

so you have

 private var _lengthCheck:Boolean = false;
 function test2_ChangeHandler(event:Event):void
 {
     if (_lengthCheck != (test2.text.length > 5))
     {
         _lengthCheck = (test2.text.length > 5);

         if (test2.text.length > 5)
             dispatch(new Event("LENGTH_GREATER_THAN_5"));
         else
             dispatch(new Event("LENGTH_LESS_THAN_5"));
     }
 }