fcOnTheWeb Logo Web technologies, made easy.

fcOnTheWeb Red DotLinks in Flash - Opening in new and current windows

There are a few ways to make a link in Flash, and ways to have the link open in a new window or in the same window. We take a look at a couple of methods you can use.

The first method we look at involves setting a piece of text as a link and using Flash's controls to do that. The second method we look at let's you set a button or a MovieClip as a link and uses ActionScript.

The first method we look at is the simplest and it involves simply using the Flash properties to set a piece of text as a link.

This method can be used for either a piece of selected text, or an entire text element. That is, it can be applied when a few words of a sentence are selected (and the link will be applied to just those words) or just selecting an entire text object, without highlighting any text inside, will set the entire piece of text as a link.

With the text selected (either a few words or an entire text object) simply enter the destination URL in the Link: field. This is, not surprisingly, where the link will go to. Nearby, either below like in our CS4 screenshot or alongside, will be a Target: field. This will either be a dropdown with some pre-allocated options or just a text field. Either way, this is the name of the window that the link will open in. We won't go into the science of named browser windows here, but if it the value is set to _blank the link will open in a new window, and if it is set to _self the link will open in the current window.

Below is a shot of the settings we have used for our example:

Link Options

You can see we have the set the Link: as http://fcOnTheWeb.com and the Target: as _blank to make the link open in a new window.

Let's take a look at the final product and the text we have linked.

Your version of Flash Player is lower than the required 10.0.0.

Click below to upgrade to the latest version and then try again.

Get Adobe Flash player

As you can see, Flash doesn't put a line under the linked text like the browser will by default, so it's often a good idea to manually add an underline to the text which is linked so the user can easily recognise it.

Clicking on the above text will open the link in a new window.

So that's plain text sorted, now let's take a look at how to link a button or a MovieClip with ActionScript.

You can download the source files we have used for this example from this link: link.zip.

ActionScript 2

This approach really doesn't require much ActionScript at all and is quite easy.

It simply revolves around capturing the click and then launching the inbuilt command to follow a URL. In ActionScript 2 this command is getURL and then we pass in a couple of parameters.

Let's take a look at the code:

btn_link.onRelease = function () {

getURL("http://fcOnTheWeb.com", "_blank");

}

As we can see, this is quite straightforward. A simple event fired onRelease of the button. And into the getURL function we pass the URL we want to navigate to and the name of the window we want it to open into. Again we use _blank to have it open in a new window and _self to have it open in the current window.

Let's take a look at it in action:

Your version of Flash Player is lower than the required 10.0.0.

Click below to upgrade to the latest version and then try again.

Get Adobe Flash player

Simple. And because this getURL is so basic to use, it can be called anywhere you like on any object you want.

And that's all there is to it. Two methods that can be used to call URLs from Flash. And can make them open in either new windows or the current window.

You can download the source files we have used for this example from this link: button_as2.zip.

ActionScript 3

This approach really doesn't require much ActionScript at all and is quite easy.

It simply revolves around capturing the click and then launching the inbuilt command to follow a URL. In ActionScript 3 this command is navigateToURL and then we pass in a couple of parameters.

Let's take a look at the code:

function launch_url(evt:MouseEvent):void {

var request:URLRequest = new URLRequest("http://fcOnTheWeb.com");

navigateToURL(request, "_blank");

}

btn_link.addEventListener(MouseEvent.MOUSE_UP, launch_url);

As we can see, this is quite straightforward. A simple event fired on the button click. We first set up a new URLRequest which is our URL. And then we pass that object into our the navigateToURL function, as well as the name of the window we want it to open into. Again we use _blank to have it open in a new window and _self to have it open in the current window.

Let's take a look at it in action:

Your version of Flash Player is lower than the required 10.0.0.

Click below to upgrade to the latest version and then try again.

Get Adobe Flash player

Simple. And because this navigateToURL is so basic to use, it can be called anywhere you like on any object you want.

And that's all there is to it. Two methods that can be used to call URLs from Flash. And can make them open in either new windows or the current window.

You can download the source files we have used for this example from this link: button_as3.zip.

ferrari_chris

Josh Schneider says:

2009-07-24 18:45:35

This is a great article, thanks for posting.
Is there a way to link to a site where a URLReferrer will be included in the request like an actual hyperlink was clicked? That way the site that you linked to can tell where you are coming from?

__________

Dave says:

2009-08-10 22:15:35

Hey this helped me out, but I'd like the mouse pointer to display the link hand when hovering over the link. Its not doing it for mine...do I need to add any extra code to get the link pointer to display on hover?

__________

ferrari_chris (http://fcOnTheWeb.com) says:

2009-08-20 08:23:32

@John:
With the testing I've done here, the referrer always comes through regardless of whether the link is a Flash text link or from ActionScript. Sorry, I can't help you there.

@Dave:
The link should display the hand cursor by default. Make sure your text is static, and if it has to be dynamic text then try making it unselectable.

__________

Cheap Ralph Lauren UK (http://cheapralphlaurenuk.1minutesite.co.uk/) says:

2014-01-18 03:07:32

Gucci Shoes UK, http://www.guccivshoesfactory.net/
Polo Ralph Lauren Outlet Online, http://www.rralphlaurenoutlet.com/
Ralph Lauren Outlet Online, http://www.ralphlaurenipolo.com/
Ralph Lauren UK, http://www.polo-outletstoreonline.com/
Beats by Dre, http://www.discountbeatsbydresale.com/
Sacs Longchamp Pairs, http://www.saclongchamppairs.com/
Canada Goose Outlet, http://www.thecanadagooseoutlet.com/
Hollister UK Shops, http://www.cheaphollistersale.co.uk/
Michael Kors Outlet Online, http://www.michaelkors.so/
Marc Jacobs Outlet, http://www.marcjacobsonsale.com/
Michael Kors Outlet, http://www.michaelkorsr.com/
North Jackets Clearance, http://www.north-faceoutletonlines.net/
Burberry Outlet Online, http://www.burbagssale2013.com/
North Clearance Outlet Online, http://www.north-clearance.com/
Coach Factory, http://www.coach-factories.com/
Coach Outlet Online, http://www.coach-purseonsale.com/
Cheap Ralph Lauren UK, http://cheapralphlaurenuk.1minutesite.co.uk/
http://marcjacobsoutlet-2014.tripod.com/
http://www.michaelkorsoutletr.com/
Michael Kors Outlet
Discount Michael Kors
http://www.michael-korsfactorystore.com/
Michael Kors Outlet
Michael Kors Factory Store
http://www.michaellkorsfactoryonline.com/
Michael Kors Outlet
Discount micheal kors


Add your comment on this article below:

Sorry, there's an error with your form entries. We really appreciate your comment, so please try again.

Form submitting now...

Name:

Website:

Email address (not displayed):

Enter your comment below: