Thursday, June 21, 2007

Using public namespace explicitly

Having same function in two or more name spaces can cause the following compiler error when trying to access the function. 1000: Ambiguous reference to foo. This error is easily generated when "using namespace " has been included in the file instead of referring to the namespace explicitly.

  public namespace myspace = "http://myspace";

import myspace;

public class TestClass

  public function foo():void
 trace("Public foo is called");

  myspace function foo():void
 trace("MySpace foo is called");

  private function fooPrivate():void
 trace("Called private function");

  protected function fooProtected():void
 trace("Called protected function");

  public function callFoo(t:TestClass):void
        // call the private/protected members on the object.


<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="" layout="absolute"

use namespace myspace;

private function testFunc():void
   var test:TestClass = new TestClass;
   //public can be also used as namespace name to call the correct function.

   // call the myspace namespace function

   var test2:TestClass = new TestClass;
   // call the function to demonstrate that private/protected functions
   // can be called on test2 object.

The above example also shows the possibility of calling private/protected functions on an object of the same class within the functions of the class. I don't think this is allowed in languages like C++. Note: As Richard has commented it is alllowed in C++ too. I think it makes sense as friend functions can access private variables of objects member functions should be able to access them too.

Tuesday, June 19, 2007

Summary customization in AdvancedDataGrid

ADG allows customization of Summary and Grouping with various callback functions and properties. One such property available on the SummaryField class is the label property which allows one to customize the property name used for the summary data. This example shows one such usage to skip displaying any estimate information at the leaf level but display a budget summary data at the Territory level. The mxml file is here.

Thursday, June 14, 2007

headerStyleName property of AdvancedDataGrid

In my previous post I said that I thought it was not possible to style the header independent of the column cells. I was wrong. I found out that AdvancedDataGrid has the headerStyleName property similar to DG which can be set and headers can be styles independently. Using that and tweaking a little bit of code I could get the following look and feel which looks really nice!

AdvancedDataGrid Summary with column grouping

I improved my previous sample with column grouping getting the following look. The new MXML can be found here. One problem I immediately noticed is that one cannot horizontally center the headerText of the columns without centering the column cell text, this is specially a problem with first column. I filed a request for this. The headerText cannot be vertically centered either. However this has been already reported requesting even more options.

AdvancedDataGrid Summary roll up sample

Here is a sample application showing Summary roll up feature in AdvancedDataGrid and GroupingCollection. The GroupingCollection takes flat data in the form of a ICollectionView object as input and generates a grouped collection based on the GroupingField information provided. The example shows grouping on the Region and Territory data fields. Of-course don't forget to call the refresh method on the GroupingCollection to make the collection to generate the grouping. If Summary is desired Summaries with SummaryRow and SummaryField information can be added to each GroupingField object. The SummaryRow has a summaryPlacement property which can take multiple values as input from the possible values of group, first and last. I have used group to show the roll up of summary values. SummaryField has a operation property which by default supports "SUM", "MIN", "MAX", "AVG" and "COUNT". ADGColumn has support for a formatter which can be used to format cell values using any Flex formatter. I have used currency formatter to place a $ symbol. ADG and ADGColumn have a style function property which can be used to set style values on a particular cell based on its data content. The example uses this to change the font color to red. Oh! ADG has loads of features. Check it out. Before I forget here is MXML file for the sample.