How to put actionscript code for a button?

Posted on 2013-10-05
Medium Priority
Last Modified: 2016-06-24
Hi Experts!

Could you please give me a way to put actionscript code for a button, accordingly with the Picture, what must be done to allow the code be entered?

img 01
Thanks in advance!
Question by:Eduardo Fuerte
  • 3
  • 3
LVL 19

Accepted Solution

quizengine earned 2000 total points
ID: 39550508
It seems likely (because the actions window is "Current selection can not have actions applied to it" that your fla is setup to use Actionscript 3 (AS3).

If for some reason you want to apply actions directly to a button, you have to use Actionscript 2 (AS2). To change your fla to AS2, goto 'File > Publish settings > Flash tab > script and change that to Actionscript 2.0

Then, select your button again, go to the Actions window and paste the following code

on (release) {
      // put the code you want to run when the button is clicked on the next line(s)

You should know that if there is other Actionscript 3.0 code in your fla, then changing the Publish settings to AS2 will probably make that code fail.... So....

You can add code to an AS3 button by placing selecting an EMPTY keyframe in the timeline (usually in a layer called 'Actions' so you can find your code again easily). Your button MUST have an instance name. Set this by selecting the button on the stage, go to the Properties panel, and type the instance name in the 'Instance name' field at the top of the Properties panel window. I'm going to assume you've named it 'Button1' in the code below.

Here is the code to use (paste into the Actions panel when you have an empty keyframe selected.

Button1.addEventListener(MouseEvent.CLICK, ButtonClick);
function ButtonClick(ev:MouseEvent):void
trace("Button1 has been clicked.");
// place any other code you want to run before the closing curly brace below

Author Comment

by:Eduardo Fuerte
ID: 39550626

After follow your very didatic instructions I created and put the code at the buttons but unfortunatelly the .swf doesn't run OK...

Could you have a look at ?

The previous version runs OK at

The fla with the modifications you suggested at:

If possible, could you take a look on what is causing this problem?
LVL 19

Expert Comment

ID: 39550701
Because I don't know what is, or is not, supposed to happen, I don't know which part is broken.

Could you please be more specific about which things should be clickable, and what should appear when you click them?
Easily Design & Build Your Next Website

Squarespace’s all-in-one platform gives you everything you need to express yourself creatively online, whether it is with a domain, website, or online store. Get started with your free trial today, and when ready, take 10% off your first purchase with offer code 'EXPERTS'.


Author Comment

by:Eduardo Fuerte
ID: 39550759
The new swf will work almost the same manner than the actual one works- the new version changed only one buton functionality.

I put the swf in production at the same place


only if you could have a look...

Works OK

The one that doens't work OK even after the code I put.
LVL 19

Expert Comment

ID: 39550791
You say that one button functionality has changed - are you able to say which button? (otherwise I can only guess, and I don't want to do that because I'll probably guess wrong)

And when you have identified the button, can you please say what you'd like that button to be doing that it isn't doing now?

Author Comment

by:Eduardo Fuerte
ID: 39552056

The only button changed is the last one
Just one thing I guess the designer done from the previous version to the actual version that is a new layer that maybe is causing the problem:

Previous version:
New version:
So ALL the buttons, even coded are for some reason not fired....

Featured Post

Get 10% Off Your First Squarespace Website

Ready to showcase your work, publish content or promote your business online? With Squarespace’s award-winning templates and 24/7 customer service, getting started is simple. Head to Squarespace.com and use offer code ‘EXPERTS’ to get 10% off your first purchase.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

This is a very simple example to help those of you who are still migrating from AS2 to AS3 understand the redesigned event model in AS3. In AS2.0, event functions (that is, the function to be performed when an event is fired) were stored as a pro…
This article describes a solution to a problem of subloading one movie into another when they have different SWF versions. Sometime back, I was working on an ActionScript project while I came across an interesting fact which I would like to share…
In this tutorial viewers will learn how to create a basic shape tween animation in Flash including shape hints for smooth animation Open a new document in Flash: Draw a shape: Select another frame (how long you want the tween to be): Right click and…
The goal of the tutorial is to teach the user what frame rate is, how to control it and what effect it has on the video.

619 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question