Thursday, October 15, 2009

Flex callLater()

The other I was working on a Form container. Where in I have few form items and a default button for submit. I was also using validators for validating the fields.
The validators are bound to the input fields, so that the 'errorString' is automatically populated for each input field. I do have submitHandler() to be triggered when the button is clicked. The order of event execution is not as desired by me. First the custom handler is triggered, next the event in the validators are triggered, which is vice-versa I wanted.

I'll put it in code what I mean:


<mx:Script>
 //this function triggers after the validations are completed
 private function onSubmit( p_evt : MouseEvent = null):void
 {
  trace(firstName.errorString);
  trace(lastName.errorString);
 }
</mx:Script>
<mx:StringValidator minLength="2" required="true" property="text" trigger="{submitBtn}" triggerEvent="click" source="{firstName}" id="firstNameValidator" />
<mx:StringValidator minLength="2" required="true" property="text" trigger="{submitBtn}" triggerEvent="click" source="{lastName}"/>

<mx:Form width="100%" height="100%" paddingLeft="5" paddingRight="5" id="form" defaultButton="{submitBtn}">
  
 <mx:FormItem label="First Name*">
     <mx:TextInput width="115" editable="true" color="0x000000" id="firstName" styleName="formInput" />
 </mx:FormItem>
 
 <mx:FormItem label="Last Name*">
     <mx:TextInput width="115" color="0x000000" id="lastName" styleName="formInput"/>
 </mx:FormItem>
 
 <mx:FormItem label="Last Name*">
  <mx:Button click="callLater(onSubmit);" buttonMode="true" id="submitBtn" />
 </mx:FormItem>
</mx:Form>

Flex Combobox styles

Setting styles to combobox is not just as simple as assigning a 'styleName' property.
The style doesn't apply that easily to the 'prompt' text. By default the font weight is bold and it screws up if the font specified in the styles doesn't have a bold face.

Ideally, it can be like this:
ComboBox {
cornerRadius: 0;
fillAlphas: 1, 1, 1, 1;
fillColors: #ffffff, #ffffff, #ffffff, #eeeeee;
font-family: Avangmb;
font-size: 11;
dropdownStyleName: comboBoxDropdownStyles;
}

.comboBoxDropdownStyles {
fontFamily: AVGARDM;
fontWeight: normal;
}