Latest tutorial: Making a Movieclip face another Movieclip or point on the stage | Ask Tutorial5!
 

Get tutorials on EMail




How to create a hyperlink in Flash using getURL() method

(66 votes)
Written by AnaS   

Is basic to create hyprelinks when you develop a website. This tutorial explaines how easy is to create a hyperlink in Flash using getURL() method for ActionScript 2.

1. Create a new Flash document and save it as FlashGetURL.fla on your computer. Go to Modify >> Document (Ctrl+J) and choose 300x200 pixels for dimensions.

2. Insert a new layer and rename the top layer actions and the bottom one button.

3. In the first frame of the button layer create a button Symbol (more at) or drag one from Window >> Common Libraries >> Buttons. Select the button on your stage, go to the Properties panel and give it an instance name of myButton_btn.

flashgeturl1.gif

4. Now go to the actions layer, open the Actions panel (F9) and put the following ActionScript code in:

myButton_btn.onRelease=function(){
getURL("http://www.tutorial5.com/", "_blank");
}

5.That's all! Hope this tutorial helps.

* Update
If you want your links to open in the same window you need to replace "_blank" with "_self"

You need to Register in order to download the FLA file.



Subscribe now via RSS feed and get all the new tutorials

written by suresh , December 10, 2007

hoe to make a glass effect button
written by thomas , December 12, 2007

i get an error saying **Error** Scene=Scene 1, layer=Button, frame=1:Line 1: Statement must appear within on handler
button.onRelease=function(){

Total ActionScript Errors: 1 Reported Errors: 1
written by sunil kaith , December 22, 2007

i get an error saying **Error** Scene=Scene 1, layer=Button, frame=1:Line 1: Statement must appear within on handler
button.onRelease=function(){
written by tt , January 14, 2008

be careful guys, the code must be in the action layer!
nice tutorial...
written by jee , January 31, 2008

This code works but when I switch from my parent website to the new hyperlinked website, it carries over the parent's background music which I did not want. Because it clashes with the new music in the new website. How can I completely close out the parent website
written by Daniel , January 31, 2008

Hello Jee,

It caries out the music in the background because the link is set to open in a new window.
To make it open in the same window modify the script from
getURL("http://www.tutorial5.com/", "_blank");
to
getURL("http://www.tutorial5.com/", "_self");
written by Daniel , January 31, 2008

For Thomas and Sunil Kaith
You are getting those errors because you placed the code in the wrong layer. You must place the code in the Actions layer!
myButton_btn.onRelease=function(){
getURL("http://www.tutorial5.com/", "_blank");
}
written by Josh , February 09, 2008

Thanks for your help Daniel.. I was having the same problem. I had no idea what you meant but the more and more I played around it made sense.

Huge thanks!!
written by casyi , February 19, 2008

ooopss ty
written by Imdbman , February 24, 2008

It didn't work.
written by genoy , March 07, 2008

I use the following code for a buttom to onclick to open test.html in a new window:

on (release) {
getURL("test.html", "_blank");
}


At first it works fine. But coming back and onclick the second time, it starts opening on the same window.

*all html files are on the same folder.

Help please
written by rminaw , March 19, 2008

i have a dragable menu, which i pull out the side, and i want to put a hyperlink button on it, but when i pu the button in the Mc it only moves the selection and doesnt hit the actual button any help
written by ALZ , March 20, 2008

I still cannot get it to work, I've copied everything exactly, my button just does NOTHING when I click it

here is my code ON the action layer:

blah3.onRelease=function(){
getURL("http://www.springsips.com", "_self");
}

I've given my button an instance name of blah 3 and its all there, but the button does not do anything

here's my fla: www.springsips.com/~corduroy/intro.fla

ANY help would be much appreciated, I can always get buttons to go between movies in flash, but I need it to go to an html website
written by Mk , March 27, 2008

This doesn't say how to create the hyperlink. Just telling somebody to copy and paste code does not teach somebody how to do something. You can give a man to fish... yada yada
written by aaron danker , March 31, 2008

How about a named anchor hyperlink? This does not seem to work for me?
ex. getURL("http://domain.com#text_link_in_page","_blank");

thanks
written by Sean , April 25, 2008

I get 1180: Call to a possibly undefined method getURL.
written by vakho , April 26, 2008

Hi! I'm getting these errors,

1119: Access of possibly undefined property onRelease through a reference with static type flash.display:SimpleButton.
1180: Call to a possibly undefined method getURL.

I'm using Flash CS3. What am I doing wrong?
written by jhann , April 30, 2008

thank you! its a big help!
written by yuyo , May 28, 2008

anyone using Flash CS3, make sure your publish settings are for AS 2.0 and not 3.0
written by sic , June 06, 2008

This does NOT work
written by Raj , June 12, 2008

Hi,

Could anybody help me? i have one movie clip button not a normal one it's a movie clip button what i need here means if somebody would click on that button, should come new pop-up, window width 500,300 window size. Please give me the action script..

Thanks

written by Dodi , July 03, 2008

Hi, If I want to call folder that contain some files inside using button or movie clip, how about the scripts?
written by Kenneth , August 03, 2008

Hi,
Thanks. It works fine.
Kenneth
written by seraquin , August 15, 2008

how about for 3.0? ...why must they change 2.0 to 3.0...they should just leave it alone. I was freaking out cause i thought it didnt work while using 3.0...why didnt this person state he was using 2.0...geez -_-
written by Sztewe , August 18, 2008

CS3 is piece of crap. In the old versions of flash you don't have to be an Actionscrip geek to add a freakin hyperlink to a flash button. you could do it by few mouse clicks.But in CS3???
This is an annoying bug in CS3, that i hope won't be in CS4
written by Sztewe , August 18, 2008

oops Sorry :( but this tutorial was great!!! Big Claps to the maker!!
But in other hand it doesen't work for me, because i am a bit noob in Actionscript
written by Sztewe , August 18, 2008

I had done it!!!! it's a bit rough but easy if you get a heng of it!
THANK YOU SOOO MUCH!!
written by Sztewe , August 18, 2008

Note to other who doesent succeded yet:
If you get an error that tells you that
1119: Access of possibly undefined property onRelease through a reference with static type flash.display:SimpleButton.
1180: Call to a possibly undefined method getURL.
Then you should change in the document propeties to ActionScript 2
Than it would do fine
written by nishith , September 03, 2008

hey guys!
would like to know how to make an email id link which when clicked upon opens the outlook express instead of any other websites?
written by Soe Htaik Aung , September 23, 2008

My Button Can't work after I add code in the action Layer.
This is my Code which I write in action layer.

ContactUs_btn.onRelease=function(){
getURL("ContactUs.html", "_blank");
}

So Please help me. How to add url and Anchor in flash button.
written by sdfsd , September 25, 2008

http://www.hackers-grounded.com come join us
written by welly , October 27, 2008

Thx. It's really work.

Anyone can help?
I want to make link & hide the name.
Ex:
www.tester.com/index.html

to

www.tester.com using getURL() method.

and

www.tester.com/about_us/index.html

to

www.tester.com/about_us

Thx
written by anup , November 02, 2008

thanks
written by kuldeep , November 24, 2008

What If I want to use network.html#maharashtra link in Flash button!
Pls help me Its Urgent
written by scorpion , December 22, 2008

nice tutorial.

but i've a problem..
i create the button, put it in the work area with all actions u said.
when i publish it as both fla and html, the fla works fine but not the html thing. i need this button of mine to be put in html.

please help me guys.
written by sundar , February 09, 2009

If i have two tabs say home and contact us..how to create a link between these two..please help me.. i am new to action script
written by Jessica , March 11, 2009

My URL link won't work either, I am using CS4, ActionScript 2.0
Here is my code:

BuyNow_btn.onRelease=function (){
getURL("http://www.apple.ca/", "_blank");
};
written by Johnhazrd , March 17, 2009

I am using Flash CS3, the reason your having address issues is because if you notice the results on your page it will show that parts of the address have been cut off... I recently learned that if you add a space to any then your address will work

example
on (release) {
getURL("G: Program Files GALA-NET Rappelz Launcher.exe","_self");
}

I think I am going the wrong way with this because I want to open a executable file but I do not want to open it through a web browser. Does anybody know how to do that?
written by Johnhazrd , March 17, 2009

wow something happened to my slashes they did not post on my last post lets see its supposed to be:

"G: Program Files GALA-NET Rappelz Launcher.exe","_self"
written by Johnhazrd , March 23, 2009

I figured it out.

# = a slash.

green_menu.onRelease = function() {
getURL("C:# Documents and Settings# Administrator# Desktop# Pelz.lnk");
}

Ok for those who like me are linking to .exe files its best to link to a shortcut that refers to a .exe. For example Rappelz requires a launcher and when I refered to the program it tried to find it on my comp and since I have the actual game on an external drive it wanted to install the game on my C drive instead of just finding it on my G drive. As a final thought refering to a shortcut is easier than i first thought and the file extension for a shortcut is ".lnk". YaY for random experience.
written by -T- , April 02, 2009

Hey all! I have been frustrated with CS3 on this hyerlink business for a while now. I have tried and tried again with most of the suggestions on here. but i still get the same errors. I am using ActionScript 1.0 & 2.0

my instance name is:

words

Here is my script:

words.onRelease = function() {
getURL("http://www.whitetangelo.com/Promotions/index.html","_self");

}

these are the errors I am getting:

1119: Access of possibly undefined property onRelease through a reference with static type flash.display:SimpleButton.

1180: Call to a possibly undefined method getURL.

What the hell am i doing wrong?
written by Switch , April 04, 2009

When I do this the address link that it creates is directed through my website address. As example of this is: http://mywebesite.ca/www.hyperlinksiteaddress.com

As a result I get a page not found error.

Any Idea why it won't write the direct http/ address to the site instead of trying to route it through my site??

Thx
written by oldiethegoalie , April 07, 2009

Hi,
Hope I am asking this question in the right forum.

I want to sell some items on a local classified ad website.
I have a webpage of my own with all my info already done and instead of typing all the info on this local ad site I would like to put a link/hyperlink? of my site onto theirs.
HOW DO I DO THAT?

PS I have no control of inserting HTML on their site.
I can only type in my info of sale.

So how do I link my site onto theirs.

Thank You
written by titut , April 11, 2009

this is a syntax error code..

on(release)
{
getURL("http://www.flash-here.com", "_blank");
}

this is a correct code..

on(release){
getURL("http://www.flash-here.com", "_blank");
}
written by Jason daniel , April 16, 2009

Hi,

Could anybody help me? i have one button that I need to my view to be able to click on that button and the Link of the next window opens up in its own window in the top left corner of the browser with a Width of 400 and a height of 300. I gues you can say I want a pop up window that is sized to the swf or html file I link it to.
Thanks
Please Help
written by Jason daniel , April 16, 2009

Hi,

Could anybody help me? i have one button that I need to my view to be able to click on that button and the Link of the next window opens up in its own window in the top left corner of the browser with a Width of 400 and a height of 300. I gues you can say I want a pop up window that is sized to the swf or html file I link it to.
Thanks

Please provide the Action script for this I amusing Adove Flash CS3
Please Help
written by jess , April 17, 2009

it dint work to me so i made it different. Try mine!! :P

on (release){;
getURL("http://www.tutorial5.com/", "_blank");
}
written by catherine , April 22, 2009

arrrghhhhhh. im making a website in CS4. i am trying to link to a site with the following URL.... http://www.kerrygreyhounds.co.uk/

I select the button and use the following code

on(release){
getURL("http://www.kerrygreyhounds.co.uk", "_blank");
}

I am pretty crap at flash so excuse my ignorance if im not "getting it".

I am applying the code by selecting the button and applying the action.
i then export it for a test run and I cant link, do I need to have a copy of the web address in the same folder as everything else?
am i actually able to test this action just in the Ctrl Enter test preview thingy??????? please help, this is driving me mad!
nothings online yet, im just doing it on my laptop for now.
can someone tell me the best hosting place too for when i do go online, im based in the republic of ireland
written by Marc (HELP!) , April 22, 2009

Hi,

I hope someone will be able to help me since I'm tearing my hrai out here...well I would be if I had some (shaved head)...anyway I digress. I've created a website with a 3D carousel from an online tutorial, everything works fine apart from the fact that all links (that is to say hyperlinks in the html and in the carousel menu) when clicked on in Internet Explorer don't open in the same window, which is obviously what I want it to do, since this is a portfolio website. Instead the browser keeps opening them in a new window.

The links work fine in Firefox and Safari just not in IE. These are the parameters I've set in XML, Actionscript and HTML:

XML - (just one urlref link as an example:






ACTIONSCRIPT:

t.urlRef = nodes[i].attributes.URLREF;

function released()
{
trace(this._parent.toolText);
getURL(this._parent.urlRef,"self");
}

HTML:

www.gutterstuffpro.co.uk



Now can anyone tell me what I'm doing wrong and why IE refuses to open the links in the same window?? Because I can't see it. I've tried the geturl parameter as:

getURL(this._parent.urlRef,"self");
getURL(this._parent.urlRef,"_mainframe");
getURL(this._parent.urlRef,"mainframe");

and I've also tried it without the speechmarks...but none of these amends the problem.

HELP!

Thanks in advance.

Marc
written by Marc (HELP!) , April 22, 2009

Sorry, for some reason the XML code didn't paste into the question I've just submitted, this is the parameter...or one of them from the xml file:




written by Marc (HELP!) , April 22, 2009

Ok this is really hacking me off now why isnt the xml code pasting onto the page when I submit this question???
written by timothy , April 23, 2009

Hello,

How can I have a link that when clicked downloads a file?

Any help appreciated
written by DanielRo , April 26, 2009

Please read other author comments before asking for support.
To make the links open in the same window modify the script from
getURL("http://www.tutorial5.com/", "_blank");
to
getURL("http://www.tutorial5.com/", "_self");
written by Kleber , May 21, 2009

saludos a todos por favor me pueden ayudar cuando subo a mi servidor web se me abre el archivo pps pero en segundos se cierra me gustaria que me ayuden

on (release) {
getURL("anexos/mod_pedagogia_p11_t20.pps", "_blank");
}
written by Leandro Levelmax , July 02, 2009

I SILVED FOR FLASH CS3 (ACTION SCRIPT 3):
________
button_Le01.addEventListener(MouseEvent.MOUSE_DOWN,mouseDownHandler);
function mouseDownHandler(event:MouseEvent):void {
navigateToURL(new URLRequest("http://www.potyguara.com.br/"),"_blank");
}
written by ArthurG , July 03, 2009

sunil kaith place your code in a frame not in the button.
written by Lisa LaT , August 20, 2009

I have a little different problem with the getURL. I have a flashing news banner with a button to go to each external story while it is displaying. I have a text and button layer for each. I have even used different button instances for each. I've had the first story pop up once, even twice or just the second story pop up once.
Can anyone please explain what I am doing wrong?

on(release){
getURL("http://www.google.com", "_blank");
}
written by Vincent Pollard , August 28, 2009

this doesn't work for me, either.
written by Richard Kranium , September 04, 2009

Hi. We downloaded the Flash file, opened it in Flash CS4 Professional, and published it without touching the action code to both google chrome and ie. The blue button wiggled when it was clicked, but didn't take us to tutorial5.com, or anywhere else. Any thoughts?
written by sarah h , October 03, 2009

is it possible to hyperlink a movieclip symbol that is moving around the page? if i apply the actionscript to an action layer, should it start at the beginning of the timeline? i've never made a flash movie before and could really use some help. here's what i'm using for my 2.0 action script per the comments above (and my symbol instance is "CAbtn" movie clip at all instances):

CAbtn.onRelease=function(){
getURL("http://www.cunninghamarchitects.com/", "_blank");
}
written by Mojojojo , October 08, 2009

Same old story, errors on hyperlinks. But I did it correct the first time from another tut and now, errors. This tut is missing something. Im a long user of Adobe products but always put off Flash until now. Its only been a few weeks now and I got most of it mastered except hyperlinks.

I found most tuts are worthless, If you want a link type with the text tool, do nothing with it and over to your properties there is a space to enter a link. But still doesnt solve something that should be simple as a over/down/hit they should have included a simple place to enter a link in that section.

How simple! Get it together Adobe! You should be beyond this.
written by tripleC , October 19, 2009

This is great! It works perfectly for me! My website is
colinpublic.com and the flash stuf will be up in a few days.
written by downtown , November 02, 2009

Hi
New to flash and need a little help. I have produced one of those "Walk Out" type videos for my website. It lives on a layer and will play automatically when the page loads. I can also get it to play when clicked but it opens on a new page and not over the graphic that the layer is on top of. Now the "boss" wants it only to load when clicking a text link, Hyperlink, on the same page as it lives. Hope I'm clear here. How do I code it so when clicked it plays on the same page?
Thank you for your time.
written by Maxmaxmax , November 14, 2009

Guys if your getting an error, check if you have the same of the button as on the script. Then try Test Movie. It works...

Cheers !
written by Kurt , December 23, 2009

I am a Noob to Flash and am having problems getting some movieclips to link to different URLs on release. I am able to get them to animate, and I am able to get them to link to an html page in the same folder, but I can?t get both functionalities to work at the same time and it is driving me crazy!! I've tried putting the actionscript in the instance object, in the action layer, and other things and nothing seems to work!?


Here is the link to the source file: http://www.myfavorites.com/fla...209_v2.fla
I believe that the actionscripting needs to be done in the "baners" movieclip, but it could also be the "Symbol 3" movieclip. I'm not sure and this is where I also need help.


Here is also a link to the .swf (http://www.myfavorites.com/flashtest/header_v8_122209_v2.swf). See, if you mouse over the first two clips, they animate, but they do not go to the HTML page if you click on them (http://www.myfavorites.com/flashtest/success1.html). The third clip will go to the page success1.html in the same folder if you click on it, but it does not animate on mouse over.


I'm using Flash CS3 as my editor and I'm using ActionScript 2.0 for the scripting.

Any help you can provide on this is most appreciated!! I'm normally pretty good at figuring out things on my own, but This problem is driving me crazy!!
written by tony123 , January 17, 2010

worked like a charm, thanks.
written by Johnhazrd , January 22, 2010

To Kurt:

I went to your test .swf and it looks to me you need to place the action script on where the animation rests at.

Say you have a 30 frame animation. If you put the action script on frame 1 as the animation plays and rests on frame 30 the action script will not be here and therefore not work.

In summation put the actionscript where the animation stops. I am going to attempt to contact you so that I can show you other ways of making this work.

written by rafiqul , January 24, 2010

i made a flash banner & it converted in a invisible btn.
now i get a getURL but give some error that such as
1.acess undefined property button_name that is btnLink
2.call to a possible undefine method
written by Bev , January 27, 2010

This is prob a stupid question, but here goes.....

I have created everything and it all works perfectly until...

When I click on the button - nothing happens.

I have put the code in the action layer - I have read all of your comments too, but nothing.

When I click on test movie, the button looks good, the arrow changes to hand (fab!) but nothing happens.

Please help

written by Diina , February 02, 2010

I have the same problem as the comment above, I have tried everything that is use to me from this forum, but still the button does not seem to work, I have even checked the script and it says there is nothing wrong with it, but still when I go to test the movie nothing happens. I am very confused!

Anyone know what I can do?
written by Faresa , February 02, 2010

how about for CS4 !!?
written by Michael Tandi , February 05, 2010

Is there any way.. that my hyperlink button from flash refer to a certain scene in another flash movie in different html page.
written by Purplekedi , September 20, 2011

Hi,
I'm having issues with the getURL simply due to the ActiveX controls. When I test my movie everything works but when I open the html or swf and click on a button, I get the message that says the attempt has been blocked. Is there a way around it?

Flash CS3 AS2

Many thanks...
written by Awais , September 25, 2011

hi, plz can anyone tell how can i add my local file (pages on my pc) on this button,

myButton_btn.onRelease=function(){
getURL("http://www.tutorial5.com/", "_blank");
}

as in this script "http://www.tutorial5.com" is hosted pages, what can i do if want to open my pages those are not yet hosted ???
written by lakshmiweb , October 03, 2011

myButton_btn.onRelease=function(){
getURL("http://www.tutorial5.com/", "_blank");
}

same code i have written. i'm getting link but mybutton animation is not working.
Please find solution?
written by may28 , October 11, 2011

i have different scenes on my flash.

some scenes have the hyperlink, i use the code:

btn_Aboutus.onRelease = function(){
getURL("http://www.facebook.com/", "_blank");
}

but it doesnt work, ive try to do this in a separate file, the code is working, is the code that i use is for in one scene only? or i've done the wrong code? pls.. answer.. i really need it.. please..

tnx ..
written by My , October 13, 2011

heey
i got cs5 and i made a game is as3.
and now i want to go in the end to a website.
how do i do it??
please help

Do you need more help? Ask now!
 

busy
Last Updated ( Sunday, 26 April 2009 )