Reputation: 1765
Given this MXML component:
<mx:TextBox id="test" text="{test2.text.length > 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" />
Upvotes: 0
Views: 517
Reputation: 17734
Can't you define "validationResult" as a get/set pair with a private variable to hold the data, and each time the setter is called with a different value then the variable, set the value, then dispatch your own custom event? This is how much of the event dispatching in the Flex framework is done.
Upvotes: 0
Reputation: 40382
<mx:Script>
<![CDATA[
private var _test2 : String = "test2.text.length > 5";
public function set test2( _test2 : String ) : void{
dispatchEvent(new Event("test2CHANGED"));
this._test2 = _test2;
}
]]>
</mx:Script>
<mx:TextBox id="test" text="{_test2}" />
Upvotes: 0
Reputation: 295
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"));
}
}
Upvotes: 1