Solved

Making CS4 Flash button link to URL

Posted on 2011-03-22
14
374 Views
Last Modified: 2012-05-11
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.
0
Comment
Question by:jknance
  • 7
  • 7
14 Comments
 
LVL 17

Accepted Solution

by:
deepanjandas earned 500 total points
Comment Utility
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
 

Author Comment

by:jknance
Comment Utility
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
 
LVL 17

Assisted Solution

by:deepanjandas
deepanjandas earned 500 total points
Comment Utility
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
 

Author Comment

by:jknance
Comment Utility
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
 
LVL 17

Expert Comment

by:deepanjandas
Comment Utility
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
 

Author Comment

by:jknance
Comment Utility
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
 
LVL 17

Expert Comment

by:deepanjandas
Comment Utility
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
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 

Author Comment

by:jknance
Comment Utility
Great, thanks.  I emailed it to you at your gmail.

Thanks.
0
 
LVL 17

Expert Comment

by:deepanjandas
Comment Utility
I will check and will let you know shortly.

Warm Regards
Deepanjan Das
0
 
LVL 17

Assisted Solution

by:deepanjandas
deepanjandas earned 500 total points
Comment Utility
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
 

Author Comment

by:jknance
Comment Utility
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
 
LVL 17

Assisted Solution

by:deepanjandas
deepanjandas earned 500 total points
Comment Utility
You have created the same function twice, change the function names to be unique.

Warm Regards
Deepanjan Das
0
 

Author Closing Comment

by:jknance
Comment Utility
Great help all the way to the end.  GREAT JOB!!
0
 

Author Comment

by:jknance
Comment Utility
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

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Introduction This article is primarily concerned with ActionScript 3 and generally specific to AVM2.  Most suggestions would apply to ActionScript 2 as well, and I've noted those tips that differ between AS2 and AS3. With the advent of ActionS…
The last time I worked with Flash and Socket connections was in AS1. A recent project required flash connecting to a Socket, and sending receiving information - we figured it would be easy enough - we all know about the socket policy documents and c…
The goal of the tutorial is to teach the user how to live broadcast using Flash Media Live Encoder and connecting it to YouTube to broadcast. Log into your Youtube account, choose live stream settings, start live stream from Flash Media Live Enc…
This Micro Tutorial will teach to how to utilize bit rate in Adobe Flash Media Live Encoder.

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now