Linking buttons in AS 3

Since this is just a movie for a button, make the stage 100 px by 35 px, as we don’t need any more room that that for this button.

Create a Layer, called “visuals” this is where all the visuals will go, and will be the layer for the button.

drag a button on the the stage(window>common libraries>buttons) pick any button you like, and place it on the stage that you just created. If you double click the button, you can get into the movie clip so that you can create new text on the button. In the button movie clip you will see many layers, but you want to concentrate on the text layer. On this text layer, double click on the text on the button, and change the text. This is not necessary at all, but I doubt you want your button to say “Enter.” However, there are situations for this.

Give the button an instance name “visit_btn”

The reason why you want to use this instance name is so that you can communicate the button with actionscript.

create a new layer called “actions”, this is where all your actionsctipt you go. To get to the actions panel right click on this layer, and picks actions, or go to Window>Actions

Type the following code in the actions window


visit_btn.addEventListener(MouseEvent.CLICK, visit);

function visit(e:MouseEvent):void {

	var request:URLRequest=new URLRequest("http://hfug.net");

 	navigateToURL(request, "_self");

}

Here is my completed swf

[kml_flashembed fversion=”9.0.0″ movie=”http://hfug.net/wp-content/uploads/2010/03/myButton.swf” targetclass=”flashmovie” publishmethod=”static” width=”100″ height=”35″]

Get Adobe Flash player

[/kml_flashembed]

If you are un sure about any of this, please leave a comment, so I can help you through this. This post was motivated from a friend that says linking in actionscript 3 takes too much code, but as you can see it is straight forward, and very easy.

3 thoughts on “Linking buttons in AS 3”

Leave a Reply