Create a Button that clicks to a Website URL in Adobe Flash using ActionScript 3

Create a button symbol or an invisible button

Obviously, in order to do this, you'll need to create a button symbol. You can draw any item on the screen or import a graphic. Select it and hit F8 to create a symbol. When you create a symbol, you'll need to give it a Library name. Also, Make sure you pick Button from the pop-up menu.

Give the button an instance name

In order to program buttons, they must have instance names. When you created the symbol, you gave it a library name, the instance name is different. It uniquely identifies the button in the timeline. To do this, go to the properties palette and look for the section, type it in there.

Create an Actions Layer

In ActionScript 3, all button code must go in the timeline. I like to create a special layer at the top of my layers list called Action layer. Click on the New Layer icon at the bottom left of your layers area and name the new layer Actions. Click on the layer to select it.

Add the code for the button

In the Actions Palette (Go to the Windows menu, then choose Actions), type in the following code:

gotourl_btn.addEventListener( MouseEvent.CLICK, onURLButtonClick);
function onURLButtonClick(event:Event ):void {
	navigateToURL(new URLRequest(''));

The important things to remember here are 1. The text gotourl_btn is whatever you called your button's instance name (NOT the library name, but the instance name in the properties palette). 2 & 3, the onURLButtonClick and the function name should match perfectly. Make sure you don't make any capitalization errors or it will fail.

blog comments powered by Disqus