Select to view content in your preferred language

Map Tool Tip and Null Values

1028
5
Jump to solution
03-28-2012 11:28 AM
ionarawilson1
Deactivated User
I am working on a web application that has two combo boxes, one for year (called yearcombo) and for measures (called myURL) for that selected year. I have two years and a bunch of measure for each year.I want to create a tool tip that when you mouse over the county you see a measure for that specific year. However the feature layer has null values and when I click on counties with null values, I get an error. Here is the error when I click on the null value:

TypeError: Error #1009: Cannot access a property or method of a null object reference.

And here is the code snippet so far

f (yearcombo.selectedItem.year == "2007" && myURL.selectedIndex == 0)
{
fLayer.definitionExpression = "DATA_YEAR_TXT like '2007'"

var graphic:Graphic = Graphic(event.currentTarget);
var htmlText:String = graphic.attributes.htmlText;
var textArea:TextArea = new TextArea();
textArea.htmlText = "<b>Measure: </b>" + graphic.attributes.ForDirIndOut.toString()
myMap.infoWindow.content=textArea
myMap.infoWindow.label = graphic.attributes.NAME;
myMap.infoWindow.closeButtonVisible = false;
myMap.infoWindow.show(myMap.toMapFromStage(event.stageX, event.stageY));
}


else if (yearcombo.selectedItem.year == "2009" && myURL.selectedIndex == 0)
{
fLayer.definitionExpression = "DATA_YEAR_TXT like '2009'"
var graphic2:Graphic = Graphic(event.currentTarget);
var htmlText2:String = graphic2.attributes.htmlText;
var mytextArea2:TextArea = new TextArea();
mytextArea2.htmlText2 = "<b>Measure: </b>" + graphic2.attributes.ForDirIndOut.toString()
myMap.infoWindow.content=mytextArea2
myMap.infoWindow.label = graphic2.attributes.NAME;
myMap.infoWindow.closeButtonVisible = false;
myMap.infoWindow.show(myMap.toMapFromStage(event.stageX, event.stageY));
}



Any ideas on how I can get rid of the error message? Thank you!
Tags (2)
0 Kudos
1 Solution

Accepted Solutions
RobertScheitlin__GISP
MVP Emeritus
Ionara,

       To avoid the null value you would do a simple line like this:

textArea.htmlText = "<b>Measure: </b>" + (graphic.attributes.ForDirIndOut)?graphic.attributes.ForDirIndOut.toString():"";


and use this same pattern anytime you check the graphic for a particular attribute.

View solution in original post

0 Kudos
5 Replies
RobertScheitlin__GISP
MVP Emeritus
Ionara,

       To avoid the null value you would do a simple line like this:

textArea.htmlText = "<b>Measure: </b>" + (graphic.attributes.ForDirIndOut)?graphic.attributes.ForDirIndOut.toString():"";


and use this same pattern anytime you check the graphic for a particular attribute.
0 Kudos
ionarawilson1
Deactivated User
To answer my own question I used try and catch methods and it worked. I  just dont understand why it didnt trace the error as my method asks it to be traced but the error is not appearing anymore. See code below


   
    if (yearcombo.selectedItem.year == "2007" && myURL.selectedIndex == 0)
    {
     fLayer.definitionExpression = "DATA_YEAR_TXT like '2007'"
    
     var graphic:Graphic = Graphic(event.currentTarget);
     graphic.symbol = mouseOverSymbol;
     var htmlText:String = graphic.attributes.htmlText;
     var textArea:TextArea = new TextArea();
    
     try{
     textArea.htmlText = myURL.selectedItem.label + graphic.attributes.ForDirIndOut.toString()
     myMap.infoWindow.content=textArea
     myMap.infoWindow.label = graphic.attributes.NAME;
     myMap.infoWindow.closeButtonVisible = false;
     myMap.infoWindow.show(myMap.toMapFromStage(event.stageX, event.stageY));}
    
     catch(error:Error) {
      trace("Caught Error: "+error);
     }
0 Kudos
ionarawilson1
Deactivated User
Thank you Robert, you always have great solutions! I am going to try that!
0 Kudos
ionarawilson1
Deactivated User
Hi Robert,

I tried that and still got the same error. Any ideas?

Here is the code snippet

   if (yearcombo.selectedItem.year == "2007" && myURL.selectedIndex == 0 && radioBtnGroup.selectedValue == 0)
    {
     fLayer.definitionExpression = "DATA_YEAR_TXT like '2007'"
    
     var graphic:Graphic = Graphic(event.currentTarget);
     graphic.symbol = mouseOverSymbol;
     var htmlText:String = graphic.attributes.htmlText;
     var textArea:TextArea = new TextArea();
     textArea.htmlText = "<b>Measure: </b>" + (graphic.attributes.ForDirIndOut)?graphic.attributes.ForDirIndOut.toString():"";
     myMap.infoWindow.content=textArea
     myMap.infoWindow.label = graphic.attributes.NAME;
     myMap.infoWindow.closeButtonVisible = false;
     myMap.infoWindow.show(myMap.toMapFromStage(event.stageX, event.stageY));}
0 Kudos
RobertScheitlin__GISP
MVP Emeritus
Ionara,

     You need to check the existence of any attribute that you attempt to use.

var htmlText:String = (graphic.attributes.htmlText)?graphic.attributes.htmlText:"";
0 Kudos