Solved

Making CS4 Flash button link to URL

Posted on 2011-03-22
14
383 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
ID: 35195335
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
ID: 35198437
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
ID: 35198760
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
ID: 35199035
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
ID: 35199359
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
ID: 35200413
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
ID: 35203676
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:jknance
ID: 35203755
Great, thanks.  I emailed it to you at your gmail.

Thanks.
0
 
LVL 17

Expert Comment

by:deepanjandas
ID: 35203775
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
ID: 35204004
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
ID: 35207182
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
ID: 35207481
You have created the same function twice, change the function names to be unique.

Warm Regards
Deepanjan Das
0
 

Author Closing Comment

by:jknance
ID: 35208316
Great help all the way to the end.  GREAT JOB!!
0
 

Author Comment

by:jknance
ID: 35208349
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
YouTube Link 10 353
Google Chrome - Where is "Enable Resource Tracking" 2 11,545
Updating Flash Player with GPO 3 348
Adobe Products Forum? 3 147
I have been doing hardcore actionscripting for some time; and needless to say I have faced a lot of problems in just understanding others' code rather than understanding what the code executes. A programmer's life can become hell when there are a lo…
In my long career of working as an actionscript developer, I had spent sleepless night often working hard to solve some small problems which actually took a lot of my development time; later found out the solutions to be a line or two. Here are s…
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…
The goal of the tutorial is to teach the user what frame rate is, how to control it and what effect it has on the video.

910 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

24 Experts available now in Live!

Get 1:1 Help Now