0

How do I make a link on a button which is in a Flash movie clip?

2
  • 3
    please specify your question.. what AS version? What have you tried? Commented Feb 24, 2010 at 16:03
  • hello sir. i am working on flash menu. in this menu i make a 4 tabs.. in each tabs i have 2 text.. in this text i have to give a link on google.com. and i also have to add a underline when my mouse over the text. i m useing a adobe flash cs3. Commented Feb 25, 2010 at 5:53

1 Answer 1

5

Assuming your button has an instance name of "myButton", on the frame where your button is in the timeline, you'll add the following (or similar) Actionscript.

AS2

myButton.onPress = function()
{
   getURL("http://stackoverflow.com", "_blank");
}

AS3

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

myButton.addEventListener(MouseEvent.CLICK, onMouseClick);
function onMouseClick(event:MouseEvent):void
{
   var request:URLRequest = new URLRequest("http://stackoverflow.com");
   request.method = URLRequestMethod.GET;
   var target:String = "_blank";
   navigateToURL(request, target);
}

Backwards compatible getURL for AS3

/**
 * Backwards compatibility for global getURL function.
 *
 * @param url     Url to go to.
 * @param method  'get' or 'post'.
 * @param target  Window target frame [ex. '_blank'].
 */
public static function getURL(url:String, target:String = '_blank', method:String = 'get'):void
{
    method = method.toUpperCase();
    target = target.toLowerCase();

    if (method != URLRequestMethod.POST && method != URLRequestMethod.GET) method = URLRequestMethod.GET;
    if (target != "_self" && target != "_blank" && target != "_parent" && target != "_top") target = "_blank";
    var request:URLRequest = new URLRequest(url);
    request.method = method;
    navigateToURL(request, target);
}

Note that in both AS2 and AS3 you could write this code in a class and set the class as the export class for your button/movieclip. This is probably a bit more complex though.

Sign up to request clarification or add additional context in comments.

1 Comment

Nice job, but to get the AS3 example you provided to work you must also add: import flash.net.navigateToURL; Thanks, Larry

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.