Main Content

You are here:

URL Buttons

Welcome to Foundation Flash's tutorials. In this tutorial, I'm going to teach you how to make a URL button. Do you remember our button that we made a couple of tutorials back?

the button we made a couple of tutorials ago

Well, we are going to be adding some ActionScript to that button to make it open up, in a new browser window, a webpage. Here is the finished product:

Well, let's get started, if you saved that button, then open it up. If not, just make another one. So, we have our operating button, but it doesn't actually do anything yet. We will have to fix that, so we will program the button, using ActionScript. In case you didn't know, ActionScript is Flash's code language, and is essential for any budding Flash developer to learn at least some ActionScript.

So, click on your button, in the main timeline, to select it. Then press F9 to open up your actions panel, where ActionScript is entered. As the button was selected when you opened your actions panel, this ActionScript will be specifically for that button. First, type in the actions panel:

on (release) {
 
}

What that is saying to Flash is:

On the release of that button, do what is between the curly brackets.

So, the structure of this code is:

when (this happens) { do this }

But obviously, we haven't put anything between the curly brackets yet. So let's do that now. Next, make your ActionScript say this:

on (release) {
        getURL(
}

We now have a getURL function, so your ActionScript will now mean:

When the button is released, go to this url:

Now, we have to tell it the URL, so put in your ActionScript:

on (release) {
        getURL("https://foundation-flash.com")
}

So now, you have told Flash that when the button has been released, that it should go to Foundation Flash. You must remember that URLs must be typed in quotation marks. But it has to now how to open this window, so next, type:

on (release) {
        getURL("https://foundation-flash.com", _blank);
}

Flash will now open a new (_blank) window and go to foundation-flash.com, when the button is released. You have also ended the statement by closing the brackets, and placing a semi-colon at the end of your statement. The semi-colon is not necessary, but it is good practice to do that, and when you format your code, Flash will put semi-colons in for you. Just to note, you can, instead of typing "_blank", type "_self", to open the webpage in the current window, but this will not work when you test your movie, only when you embed your .swf into a webpage, which is why it is most common, at least when testing, to type "_blank".

Well, that's all for this tutorial, thank you for reading, and I hope you will join me for my next tutorial,

Leon.