Making CS4 Flash button link to URL

Hello,

Can someone please tell me the exact code so that a button in Flash CS4 will go to a URL when clicked.

Please give the code and explain and I may need to follow up, because I have tried a few things.

Thanks very much.
jknanceAsked:
Who is Participating?
 
deepanjandasConnect With a Mentor Commented:
Select the button and give it an instance name from the properties panel (say the instance name is linkBtn).

Then open the actions frame by pressing F9.

Place this code:
//do necessary imports for MouseEvent, URLRequest and navigateToURL;
linkBtn.addEventListener( MouseEvent.CLICK, onClickHandler, false, 0, true );

function onClickHandler( event:MouseEvent ):void{
    var request:URLRequest = new URLRequest( "http://www.google.com" );
    navigateToURL( request, "_blank" );
}

Open in new window


Warm Regards
Deepanjan Das
0
 
jknanceAuthor Commented:
Hi Deepanjan,

Thanks for your response.  I tried it and got an error code, which I am attaching.

I gave the button an instance name and put it in the code.  Are you able to see the problem?

Thanks. Flash Compiler Error Code
0
 
deepanjandasConnect With a Mentor Commented:
First Select the instance, press F9, cut the whole piece of code, close the action panel, deselect the object.

Select the frame, press F9 and then paste the code.

Add the following lines first:

import flash.events.MouseEvent;
import flash.net.URLRequest;

Warm Regards
Deepanjan Das
0
Easily Design & Build Your Next Website

Squarespace’s all-in-one platform gives you everything you need to express yourself creatively online, whether it is with a domain, website, or online store. Get started with your free trial today, and when ready, take 10% off your first purchase with offer code 'EXPERTS'.

 
jknanceAuthor Commented:
I followed your instructions and got another error code.  I am attaching another image to show the error code, my timeline set up and the code that I pasted into the action area.

Thanks again for helping. Timeline, error code and code
0
 
deepanjandasCommented:
I guess you are using AS3.0.

Kindly share your fla, as the code seems to be fine, so there might be some other reasons.

Warm Regards
Deepanjan Das
0
 
jknanceAuthor Commented:
Is there a way to do that privately since it is a file for a client? Can I delete the file after you have looked at it and we would just post the solution at the end, so everyone could see that?

Thanks
0
 
deepanjandasCommented:
I am not sure if you can delete the file. Alternatively you can email me and I will post the so;ution here.
You will get my email address from my blog.

Warm Regards
Deepanjan Das
0
 
jknanceAuthor Commented:
Great, thanks.  I emailed it to you at your gmail.

Thanks.
0
 
deepanjandasCommented:
I will check and will let you know shortly.

Warm Regards
Deepanjan Das
0
 
deepanjandasConnect With a Mentor Commented:
As I guessed it right, you have been using as2.

So do the following:
Go to File > Publish Settings >
Select player as Flash Player 9, script as Actionscript 3 and press OK.

Now compile.

Warm Regards
Deepanjan Das
0
 
jknanceAuthor Commented:
GREAT.  That worked.  One more quick question, please, and then it will be solved.

I have two more buttons which I put on different layers and then applied the same code to each, changing only the button instance name in the code and the URL and got this error code.  Do you know what I should change to have more than one button?

Thanks. Duplicate error code
0
 
deepanjandasConnect With a Mentor Commented:
You have created the same function twice, change the function names to be unique.

Warm Regards
Deepanjan Das
0
 
jknanceAuthor Commented:
Great help all the way to the end.  GREAT JOB!!
0
 
jknanceAuthor Commented:
Thank you so much Deepanjan.  I was able to get everything working.  

For everyone, the final code for each button needs to have a different "onClickHander" name  (such as onClickHandler1, onClickHandler2, etc) for each button.  It appears twice in the code.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.