Select to view content in your preferred language

numberformatter within an inforenderer?

689
2
09-09-2010 01:49 PM
TracySchloss
Frequent Contributor
I have an inforenderer set up to be called as a click function on my map and open an infowindow.  This works fine, but some of the data I'm calling are numbers.  I'd like to be able to format the numbers with commas, but I'm having trouble calling the number formatter from within my inforenderer component.  I'm getting an error "Access of undefined property gridFormatter". 

The definition for the number formatter is <mx:NumberFormatter id="gridFormatter" useThousandsSeparator="true" thousandsSeparatorTo="," precision="0" />

I'm trying to call it within this section of code:

      <mx:Component className="MyCountyWindowRenderer">
     <mx:VBox verticalGap="-5">
      <infoClasses:InfoWindowLabel styleName="myInfoTitle" text="{data.NAME2}" width="150%"/>
      <mx:Label text='Total Children under 72 Months: {data.POPULATION}' />
      <mx:Label text="{gridFormatter.format(data.POPULATION)}" />
   <mx:Label text=  "Number Tested:  {data.TESTOUTCOME}" />
   <mx:Label text=  "Age 0-35 Months Tested:  {data.TEST_0_35}" />
   <mx:Label text=  "Age 36-71 Months Tested:  {data.TEST_36_71}" />
   <mx:Label text=  "Number Elevated:  {data.ELEVATED}" />  
   <mx:Label text=  "Test Rates per 1000:  {data.RATE}" />
          </mx:VBox>
   </mx:Component>

The line <mx:Label text='Total Children under 72 Months: {data.POPULATION}' /> is how it appears now.  The line right below is just my test to see if I can call the formatter at all.

It seems like the component is getting built before FLEX knows the numberformatter exists.  I don't know if that's what's happening and if so, if there is a way to change the order so that the number formatter exists before the component tries to call it.
Tags (2)
0 Kudos
2 Replies
RobertScheitlin__GISP
MVP Emeritus
Tracy,

   The formatter has to declared inside the Component. A component basically creates it own memory space and cannot reference things out side of itself.
0 Kudos
TracySchloss
Frequent Contributor
Got it!

So this worked: 
      <mx:Component className="MyCountyWindowRenderer">
     
     <mx:VBox verticalGap="-5">
      <infoClasses:InfoWindowLabel styleName="myInfoTitle" text="{data.NAME2}" width="150%"/>
      <mx:Label text='Total Children under 72 Months: {data.POPULATION}' />
      <mx:NumberFormatter id="labelFormatter" useThousandsSeparator="true" />
      <mx:Label text="{labelFormatter.format(data.POPULATION)}" />
   <mx:Label text=  "Number Tested:  {data.TESTOUTCOME}" />
   <mx:Label text=  "Age 0-35 Months Tested:  {data.TEST_0_35}" />
   <mx:Label text=  "Age 36-71 Months Tested:  {data.TEST_36_71}" />
   <mx:Label text=  "Number Elevated:  {data.ELEVATED}" />  
   <mx:Label text=  "Test Rates per 1000:  {data.RATE}" />
          </mx:VBox>
   </mx:Component>
0 Kudos