very simple - hyperlink

1607
4
07-26-2010 11:59 AM
LynnCarlson__GISP
Occasional Contributor
Hello,

Brand new to Flex (or any programming for that matter) and I am trying to do something I know must be very simple, but it is eluding me.  I am hoping someone might be able to take a moment to explain what to do.

I have a point geodatabase feature class with an attribute Rpage.  The value of this attribute for each point is a different URL.  The format of the URL is standard http://blah.blah.blah/blah/

I have been able to modify one of the Flex samples (Feature Layer > InfoWindow On Click) so that  I can click on any point, and see an infowindow with several attributes I want to see, including the field Rpage.  The value for the point clicked shows the http://blah.blah.blah/blah/ as text in the infowindow, but it is not clickable.

This is done by making the point feature class a feature layer, and then using outfields and {data.Rpage} in a VBox.

However, I would like to somehow make the text become a clickable hyperlink.

I tried to create a button within the VBox itself that makes up the infowindow which calls a navigateToURL function.  This didn't work.  When the button is clicked, it is unable to even find the click event function much less go to the correct url.

So now my thought is to somehow pass the outfield {data.Rpage} value (Rpage is the 4th item in the Array) that appears in the infowindow (the http://blah.blah.blah/blah/) to a button that sits outside the map.  Can't get this to work either.

Here is my code:

public function theRpage_clickHandler(event:MouseEvent):void
   {
    var myArray:Array = new Array(fLayer.outFields);
    var theRpageLink:StringField = myArray[4];
    var theRpageURL:URLRequest = new URLRequest('{theRpageLink}');
    navigateToURL(theRpageURL, "_blank");
   }

When the button is clicked, a new browser window opens, but I get a message "can't find the file at /C:/Users/Lynn/Adobe Flash Builder 4/testwver2/bin-debug/{theRpageLink}".

I've tried several variations on this idea with no luck.  What am I doing wrong?  Or is this not possible?

Alternatively, is there a way to format the http://blah.blah.blah in the attribute field itself so that it is rendered as a hyperlink in the infowindow?  I tried <a href></a> tags but that didn't work.

Thanks very much in advance if you can provide any assistance.

Sincerely,
Lynn
0 Kudos
4 Replies
by Anonymous User
Not applicable
Original User: laosuey

Strangely enough, I'm trying to work this one out as well. I have email addresses in a database and am trying to create clickable links from them in an infoWindow. I've been tinkering with the "htmlText" property, but haven't succeeded. I think maybe using html within a htmlText tag instead of actionscript/mxml to look at the database it might work. Or maybe using php... but I'll have to do some research into this. Hopefully someone's already worked out this problem. We'll see.
0 Kudos
ReneRubalcava
Frequent Contributor
There are a couple of ways to approach it, but you are very close. Because you have the {theRpageLink} inside single quotes, it thinks that's the exact string you want to send.
If you do new URLRequest(theRpageLink); that should work if theRpageLink is a well formed URL string.

If you are using the infoWindowRender you should be able to pass the string directly.


<esri:infoWindowRenderer>
 <fx:Component>
  <mx:VBox backgroundColor="0xffffff"
     color="0x444444"
     label="Parcel {data.PARCELID}">
   <mx:Label text="URL: {data.Rpage}" click="theRpage_clickHandler(data.Rpage)"/>
  </mx:VBox>
 </fx:Component>
</esri:infoWindowRenderer>

private function theRpage_clickHandler(url:String):void
{
var theRpageURL:URLRequest = new URLRequest(url);
navigateToURL(theRpageURL, "_blank");
}


I haven't tested this example, but it should work.
0 Kudos
by Anonymous User
Not applicable
Original User: thejones23

Lynn.

Can you post the mxml code you are using? At first glance I would recommend looking into a link button to handle this. How many URLs will be returned? Is it only one every time? Can there be more than one?

I had a similar situation and for my application I made an item renderer based on a link button. This contained my navigate to URL for a click event.

Styled like a hyperlink:

<mx:LinkButton xmlns:mx="http://www.adobe.com/2006/mxml"

label="{data.rPage.toString()"  toolTip="Click to open: {data.rPage}" color="blue" fontWeight="bold" click="{navigateToURL(new URLRequest(data.rPage));}">
</mx:LinkButton> 


Saved that file as its own mxml and the referenced it as an item renderer in my info window.
Mine was in a datagrid, but a list might look better.

infowindow:
<mx:VBox width="100%" verticalScrollPolicy="auto">
  <mx:DataGrid  
   id="dg1"
   width="100%"
   dataProvider="{whatever gives you the data}"  
   
   <mx:columns>
    <mx:DataGridColumn dataField="rPage"   headerText="rPages" itemRenderer="com.esri.solutions.flexviewer.myrPageitemrenderer"/>
   </mx:columns>
  </mx:DataGrid>
 </mx:VBox>


There may be a much easier solution so maybe posting your mxml will help.
0 Kudos
LynnCarlson__GISP
Occasional Contributor
Thank you SO VERY much!  I've got it working now and it is a beautiful thing.  I've got three instances now of the Research Page link - a plain label, a Link Button, and a regular Button.  All three point to the same click handler event, just in case others might want to see the options.

You guys are life savers - thanks again for taking the time to help out a total novice.  I appreciate it very much.

Sincerely,
Lynn

<esri:infoWindowRenderer>
    <fx:Component>
     <mx:VBox backgroundColor="0xffffff"
        color="0x444444"
        label="Information">

      <fx:Script>
       <![CDATA[
        protected function rPage_clickHandler(event:MouseEvent):void
        {
         var theRpageURL:URLRequest = new URLRequest(data.Rpage);
         navigateToURL(theRpageURL, "_blank");
        }
       ]]>
      </fx:Script>

      <mx:Label text="Location: {data.LocusName}"/>
      <mx:Label text="Faculty Name: {data.FacStaff}"/>
      <mx:Label text="Department: {data.Dept}"/>
      <mx:Label text="Topic: {data.Topic}"/>
      <mx:Label text="Research Page: {data.Rpage}" click="rPage_clickHandler(event)"/>
      <mx:LinkButton label="{data.Rpage.toString()}" toolTip="{data.FacStaff}'s Research Page" click="rPage_clickHandler(event)"/>
      <mx:Button label="{data.FacStaff}'s Research Page" click="rPage_clickHandler(event)"/>
      <mx:Label text="Poster: {data.gallery}"/>
     </mx:VBox>
     
    </fx:Component>
   </esri:infoWindowRenderer>
0 Kudos