3 Replies Latest reply on Dec 14, 2007 4:43 PM by jspiro

    Problems with builtin properties concerning "null" values

    Constantin Ehrenstein
      Hi there,

      I am running into severe problems the behaviour of Flex concerning null values, especially with Flex components (ViewStack and corresponding panels) and Flex Classes (such as StringUtil) when the ActionScript code tries to access a component which is in the process of initialization or creation.

      For example, I am working on a member database with several panels. One of them is an overview of all members (using DataGrid), another one is the detail view for a selected member.

      When the overview Panel is visible, I want to update the fields on the details panel (and others, too) as soon as I click on a row in the member overview. What I do to achieve this is adding an itemClick event listener, in which I pull values from a database to compose a Member class instance with all the details I have defined for a person entity.

      I would expect that even with lagged creation of the other ViewStack panels (the default "creationPolicy" setting) there would be some mechanism to prevent other event handlers to access the not-yet-created objects and UIComponents.

      But the compiler keeps complaining about trying to access a member of a null value.

      The same thing occurs when I use the com.adobe.flex.extras.controls.AutoComplete component. After an update of the dataProvider, the component fires a sequence of refresh-and-update events, leaving the text property at a "null" value inbetween, and tries to access a length property of that text property—which, in turn will again cause a runtime error.

      I had the same problem when I wanted to trim values I retrieved from a database using the StringUtil.trim() function. Everything went fine for strings, but the compiler would give up on null values (which are quite common when retrieving data from a database).

      In some cases (e.g. StringUtil), I can rule that behaviour out by coding something like StringUtil.trim(value || '') [logical OR with an empty string], but I cannot and don't want to mess with the code of the Flex Components, whether they are extras or not.

      So, do you know any workaround?

      Please, please help me on this.

      Best regards