Sunday, March 04, 2007

The Flex compiler doesn't spot name conflicts

Beware! The Flex 2.0.1 compiler appears not to notice the reuse of the same identifier if decalred as both static and non-static in (what in any other language would be) the same namespace. The equivalent throws a hard compile-time error in both .NET 3.0 and in J2SE 5. The following example compiles without error. Is this a bug or is it supposed to be like this in AS3?

Saturday, March 03, 2007

Is Flex's valueCommit dispatched at the right time?

The more I work with validators, the more concerned I am about whether TextInput's valueCommit event is raised at the right time. You could imagine a scenario where a TextInput's text property is only committed when the user is happy with the input and moves focus to another component, at which point the valueCommit event is dispatched. Unfortunately that's not how the TextInput component works. In fact, the TextInput component updates it's text property (and anything bound to its text property) after each key depression. Hence its actually "committing" its "value" after each key depression (when the change event is dispatched). This makes no sense to me at all. Either the valueCommit event is badly named or its dispatched at the wrong time in the live cycle of this component. Thoughts?

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" backgroundColor="white" backgroundImage="">
<mx:Script>
<![CDATA[
private function onChange() : void
{
trace( this.textInput.text ) ;
}

private function onValueCommit() : void
{
trace( "onValueCommit()" ) ;
}
]]>
</mx:Script>
<mx:Label text="{this.textInput.text}" />
<mx:TextInput id="textInput" change="this.onChange()" valueCommit="this.onValueCommit()" />
<mx:TextInput />
</mx:Application>