hyperlink in flex

Adding a simple hyperlink in flex is not as simple as using a getURL method in flash.

It's not that much more complicated, but enough to confuse a beginner because it uses a method that takes a particular type of object (URLRequest) as its parameter insted of a string for the URL. So you need to create the URLRequest first before you can call the method to take the user to that URL (the method is called navigateToURL).

If you want to write it all in one line, you can do it as follow (example below show you how to apply the hyperlink to a LinkButton object):

<mx:LinkButton id="sample_button" label="click me!" click="navigateToURL(new URLRequest('http://finance.yahoo.com'), '_blank')" /> 

I find this to be the easiest and quickest way to do this, but it might not be the best way to do it especially if the url is dynamic.

You should also try out the way Adobe folks recommend in the flex documentation so you'd understand the difference. 

4 Responses to “hyperlink in flex”


  1. […] to use the click handler and navigateTo method as shown in my previous blog entry hyperlink in flex […]

  2. Danny,

    Thanks!

    Thanks especially for having the wit to title your post “hyperlink in flex” which gets this page super high ranking on google searches using the terms: hyperlink flex

    Also thanks for the link to the related Adobe documentation page. Very professional. (btw, that Adobe doc page no where uses either of the words link or hyperlink. Net result, that Adobe doc page will never show up on google searches using the terms I mentioned: hyperlink flex).

    g

  3. The above has problems when the URL is to an office document. IE prompts with Open, Save & Cancel buttons, when you access an office document and the above seems to leave the pop-up window open when you choose Save or cancel. Open is fine. Has any one seen this behavior?

    Raj.

  4. Cool, it was very helpful…! Perhaps i cant get y u said “but it might not be the best way to do it especially if the url is dynamic.”

    It worx great for me if i use the variable name instead of URL.


Got something to say?