Flash Button Action Script 3

New to action script 3 and looking to make your button link to a website, add your movie clip and give it the instance name of – myButton

Then add this code to your actionscript frame and update the url as required.

myButton.addEventListener(MouseEvent.MOUSE_UP , myButtonClick );

function myButtonClick(event:MouseEvent):void
{

var yourURL:URLRequest = new URLRequest(“http://www.elitegd.com”);
navigateToURL( yourURL , “_self”);
}

If you have mulitple buttons just duplicate the code and add a number to your vars and instance name.

If your looking to link to a different frame just change the middle var request

var yourURL:URLRequest = new URLRequest(“http://www.elitegd.com”);
navigateToURL( yourURL , “_self”);

to

gotoAndStop(2);

Hopefully this will help you to get control of one of the basic tasks that requires just a bit more code in Action Script 3.

Note for the _self to work i did have to upload to a webserver to test and it worked correctly offline using _blank worked correctly.

5 Responses to “Flash Button Action Script 3”

  1. [...] code Developer obfuscates | encrypts the code User hits page, downloads embedded blob Flash Button Action Script 3 – blog.elitegd.com 04/22/2009 April 22nd, 2009 Goto commentsLeave a comment New to action script 3 [...]

  2. big says:

    This did not work for me. Just keeps opening in a new window. Hummmm. Grrrr.

  3. big says:

    Got it. Thanks.

  4. big says:

    My Final looks like this:

    Button1.addEventListener(MouseEvent.MOUSE_UP, goLayersSite1);
    Button2.addEventListener(MouseEvent.MOUSE_UP, goLayersSite2);
    Button3.addEventListener(MouseEvent.MOUSE_UP, goLayersSite3);

    function goLayersSite1(Event:MouseEvent):void {
    var layersURL:URLRequest = new URLRequest(“http://www.website.com/index.html”);
    navigateToURL(layersURL, “_self”);
    }

    function goLayersSite2(Event:MouseEvent):void {
    var layersURL:URLRequest = new URLRequest(“http://www.website.com”);
    navigateToURL(layersURL, “_blank”);
    }

    function goLayersSite3(Event:MouseEvent):void {
    var layersURL:URLRequest = new URLRequest(“http://www.website.com/commercial_industrial.html”);
    navigateToURL(layersURL, “_self”);
    }

  5. Is it still opening up in a new window on you? Testing offline in the flash it’s self can cause that if you aren’t testing in a browser. As i said I did have to upload it for my _self to work.

    Let me know as your code looks right.

    Note: Also i don’t normally edit comments but i did change the urls you had posted as they could have been offensive to some visitors of the website.