Showing posts with label adobe flex. Show all posts
Showing posts with label adobe flex. Show all posts

Sunday, November 16, 2008

Focus in all cases

Have you also noticed that Flex draws a focus border around its components when you give them focus using the keyboard (by using the tab button)?

Great but why is the focus border not drawn when using the mouse to give a component the focus?

The solution is simple: extend the existing components and force the border drawing yourself:

<mx:CheckBox
      xmlns:mx="http://www.adobe.com/2006/mxml"
      focusIn="onFocusIn()">
<mx:Script>
//
// Support to draw the focus border on focusIn
//
private function onFocusIn(): void
{
      this.drawFocus(true);
}
</mx:Script>
</mx:CheckBox>

Tuesday, January 22, 2008

Taming your combobox width

Recently I discovered that setting a combobox to width="100%" doesn't mean the combobox won't grow bigger than the width of its container. If the text cannot be completely displayed your combobox becomes wider than 100%. You can use the following construction to tame its width:

<mx:canvas id="cnvs" width="100%" resize="cb.width = cnvs.width">
  <mx:combobox id="cb" text="this is a rather long combobox text" />
</mx:canvas>

Simply add a canvas around the combobox and explicitly set the width of the combobox to the width of the canvas through the resize event of the canvas. This solution works because the problematic behaviour only occurs when using a percentage width.


The same applies to the Label component (and probably some other components as well).

Saturday, July 28, 2007

Getting .NET datasets in Flex through webservices

The current support in Flex for .NET datasets is rather 'limited' to say the least. This is a pitty because most .NET developers make use of datasets and the missing support currently prevents major adoption of Flex by the .NET community.

Although this solution doesn't add complete dataset support to Flex it at least allows you to get the records of a .NET dataset (or a datatable) in Flex through an easy webservice call.

Up till now the typical suggestion is to create a class in .NET that matches the datatable layout, create an array based on this class and fill the array with the records of the datatable.

There is however a much easier solution. Your WebMethod in .NET should look like this:

[WebMethod]
public XmlDocument GetAllUsers()
{
dsBC dsBC1 = new dsBC();
// here you should fill the datatable with database records
return GetXml(dsBC1.bcUser);
}

public XmlDocument GetXml(DataTable dt)
{
System.IO.StringWriter sw = new System.IO.StringWriter();
dt.WriteXml(sw);
sw.Close();
XmlDocument xd = new XmlDocument();
xd.LoadXml(sw.ToString());
return xd;
}

When calling the GetAllUsers web method from Flex you can simply bind for example a datagrid to the event.result object.

Dates are returned in W3C format by .NET! Therefore you should convert them to 'real' Flex dates by using the DateUtil routines in corelib.