How to put actionscript code for a button?

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!
Eduardo FuerteDeveloper and AnalystAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

quizengineCommented:
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
}
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Eduardo FuerteDeveloper and AnalystAuthor Commented:
Hi!

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 ?
http://www.espiriplug.com.br/index_EE.php

The previous version runs OK at
http://www.espiriplug.com.br/

The fla with the modifications you suggested at:
http://www.espiriplug.com.br/FLA

If possible, could you take a look on what is causing this problem?
0
quizengineCommented:
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?
0
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

Eduardo FuerteDeveloper and AnalystAuthor Commented:
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

http://www.espiriplug.com.br/FLA

only if you could have a look...

Works OK
siteespiriplug_2012.fla

The one that doens't work OK even after the code I put.
siteespiriplug_2013.fla
0
quizengineCommented:
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?
0
Eduardo FuerteDeveloper and AnalystAuthor Commented:
Hello!

The only button changed is the last one
01
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:
2
New version:
3
So ALL the buttons, even coded are for some reason not fired....
4
http://www.espiriplug.com.br/index_EE.php
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Adobe Flash

From novice to tech pro — start learning today.