first thanks to dan for his answer. I tried it, and it didn't work.
However, dan's post pointed me to the right direction.
First, to place you in a better context, let me show the main mxml file (SimpleCart.mxml):
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/halo"
xmlns:ctrl="controls.*"
xmlns:cart="cart.*"
minWidth="1024" minHeight="768" >
<s:layout>
<s:BasicLayout/>
</s:layout>
<fx:Style source="SimpleCart.css"/>
<ctrl:NewItem id="buttonAddItem" x="9" y="15" width="394" height="27"/>
<cart:SmartShoppingCart x="8" y="47" width="378"/>
</s:Application>
I think the problem is that the component grouping the Label, TextInput and Button -called NewItem- didn't get the focus, although the TextInput control did.
So, I simply added a call to this.SetFocus, to set the focus to the NewItem component, before setting the focus to the TextInput control.
The source code for the working version of NewItem is this (look for the //Solution comments to find the changes):
<?xml version="1.0" encoding="utf-8"?>
<s:HGroup xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/halo" >
<fx:Script>
<![CDATA[
protected function newItemHandler():void
{
import cart.ItemAddedEvent;
import flash.external.ExternalInterface;
var e : ItemAddedEvent = new ItemAddedEvent( "->" + textInputItemDescription.text );
textInputItemDescription.text = "";
// *** Solution begins here
this.setFocus();
// *** Solution ends here
textInputItemDescription.setFocus();
textInputItemDescription.setSelection(0,0);
dispatchEvent( e ); // Bubble to parent = true
}
]]>
</fx:Script>
<fx:Metadata>
[Event(name="ItemAddedEvent",type="cart.ItemAddedEvent",bubbles=true)]
</fx:Metadata>
<mx:Label text="Item description:"/>
<s:TextInput id="textInputItemDescription" enter="newItemHandler() "/>
<s:Button click="newItemHandler()" label="Add to cart"/>
</s:HGroup>
Best Answer
As always I suggest while managing in color and properties use Flex Style Explorer create a stylesheet.css, put it into src folder and then call it by the following statement: